Using classes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • apedosmil8
    New Member
    • Apr 2007
    • 15

    Using classes

    I am having problems with using classes. I'm not sure why this program will not run. I have pointed out the problem.

    Thanks

    #include <iostream>
    #include <iomanip>
    #include <cmath>
    using namespace std;

    class Student
    {
    private:

    char lastname[40];
    char firstname[40];
    char id[10];
    double gpa;
    int score;


    public:

    Student(char lastname[], char firstname[], char id[], double gpa, int score); //the constructor

    void showStudent();

    void setName(char newFirst[], char newLast[]);

    void setID(char newID[]);

    int setGPA(double newGPA);

    int setScore(int newScore);

    char getDecision();

    };

    int main()
    {

    Student stu1 (Thomas, James, 55443 , 3.0, 1350 ); //This is the problem :(


    }

    /*************** ******/

    Student::Info(c har lastname[], char firstname[], char id[], double gpa, int score)
    {



    }

    /*************** ******/

    void Student::showSt udent()
    {

    cout << setiosflags(ios ::fixed) <<setprecision( 1);

    cout << setiosflags(ios ::left);

    }
  • cbbibleboy
    New Member
    • Apr 2007
    • 29

    #2
    Though you have a constructor (good) you're not doing anything with it. Your constructor should have code in it that will use those values. Also, the string variables should be passed inside quotes.

    P.S. I believe --though I'm not sure-- common practice is to use "char* myString", not "char myString[]", though I think both will work.

    Comment

    • apedosmil8
      New Member
      • Apr 2007
      • 15

      #3
      I'm confused..

      From my notes they have a similar constructor with void functions afterwards.

      Our assignment shows using [] so I'm guessing its ok. This stuff is over my head right now.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        This code:
        Code:
        Student stu1 (Thomas, James, 55443 , 3.0, 1350 ); //This is the problem
        should be:
        Code:
        Student stu1 ("Thomas", "James", 55443 , 3.0, 1350 ); //This is the problem
        The notation
        Code:
        char lastname[]
        means that lastname is a array of char. In C++ the name of the array, inthis case lastname, is the address of element 0. Element 0 of a char array is a char and the address of a char is a char*. Therefore, these are equivalent:
        Code:
        char lastname[]
         or
        
        char* lastname

        Comment

        Working...