Struct and Class

closed account (SwqGNwbp)
Hi, I have to do this program today but I'm still reading previous lessons and cannot do it today. I appreciate anyone who can help me today:


Here are the definitions for the struct type and the class type:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
struct Student{
    string name;
    double gpa;
}; // struct Student

class Student1{
public:
    // ctor
    Student1( const string & name, double gpa );
    // accessors
    string getName() const;
    double getGpa() const;
    // mutators
    void setName( const string & name );
    void setGpa( double gpa );  //  C&D if not in [0,4]
    // other member functions, analogous to the functions that struct Student uses
    void show() const;  //  output name and gpa
    void input();
private:
    string myName;
    double myGpa;
}; // class Student1 


Here are the prototypes for 2 functions you are to write that work with Student structs:

1
2
void show( const Student & stud );
void input( Student & stud );


show’s job is to output a line that looks something like
Joe 3.8
(I don’t care how many digits are displayed after the decimal point. You may assume that the name consists only of a single word.)

input’s job is to input a name and gpa, and put them in the fields of the Student. No prompt required.
For instance, if the user types
Joe 3.8
then the input function will set the arg struct to hold Joe and 3.8.
If the user types
Joe blah
then the input function will C&D.

Thank you!
What is "C&D"?
closed account (SwqGNwbp)
complain and die
This is fairly straightforward thing to implement

show basically prints the name and gpa. Well then declare the method and use cout to print the student's name and gpa...literally should take you 2 mins to write out the body of both functions depending on how slow a typist you are
closed account (SwqGNwbp)
I'm sure I can do it in 2 min after I finish Struct & Class chapter, but not now. I need this today.
Last edited on
Well maybe next time you wont slack off then? This is a site to HELP not to give a FREE ride. You won't get anywhere in life by copying other peoples work. It's called plagiarism and being lazy.

I'm sure if you can make the declarations you can make the definitions fairly easy.


*edit

Seems like you do this often and take advantage of people.

http://www.cplusplus.com/forum/beginner/110234/
Last edited on
@giblit, but sometimes copying can benefit you if you decide to learn from what you have copied. Then suddenly you have the knowledge and can reproduce a solution given a similar problem.

This does not cover the fact that the implementation OP needs is fairly basic one line code and does not need to depend on someone else to do it for him/her.

@Op did you try to google a solution to your problem? What have you attempted? What failed/worked half the time? Compiler warnings? Help us help you, join the good side. We have brownie squares
Last edited on
Topic archived. No new replies allowed.