Hi guys im getting some errors here and cant seem to find why?

#include <iostream>
#include <iomanip>

using namespace std;

class Student{
public:
Student (Mary, 100, 99, 88, 1);
void getInfo();
void showInfo();
private:
string name;
double test1, test2, test3;
int idNum;
};
Student::Student (string n, double t1, double t2, double t3, int i)
{
name = n;
test1 = t1;
test2 = t2;
test3 = t3;
idNum = i;
}

Student::getInfo(){
cout<<"Enter name, three tests grades and ID ";
cin>>name>>test1>>test2>>test3>>idNum;
}
Student::showInfo(){
cout<<fixed<<setprecision(2)<<name<<"\t\t\t"<<idNum<<"\t\t\t"<<test1<<"\t\t\t"<<test2<<"\t\t\t"<<test3<<"\t\t\t" <<(test1*test2*test3)/3<<endl;
}
int main()
{
 Student s1, s2, s3;
s2.getInfo();
s3.getInfo();
s1.showInfo();
s2.showInfo();
s3.showInfo();
 return 0;
}

First of all... when posting something like this, you should be explicit as to what type of errors you're getting. It will help for faster problem analysis and problem solving.

Second, please indent your code so it's easier to follow.

Lastly, it does help to tell us what compiler you're using when you post a question.

class Student{
public:
Student (Mary, 100, 99, 88, 1);
void getInfo();
void showInfo();
private:
string name;
double test1, test2, test3;
int idNum;
};
Student::Student (string n, double t1, double t2, double t3, int i)
{
name = n;
test1 = t1;
test2 = t2;
test3 = t3;
idNum = i;
}

Student::getInfo(){
cout<<"Enter name, three tests grades and ID ";
cin>>name>>test1>>test2>>test3>>idNum;
}
Student::showInfo(){
cout<<fixed<<setprecision(2)<<name<<"\t\t\t"<<idNum<<"\t\t\t"<<test1<<"\t\t\t"<<test2<<"\t\t\t"<<test3<<"\t\t\t" <<(test1*test2*test3)/3<<endl;
}

I can see a few issues with your code.

First of all, in your class Student, why is it that your Constructor prototype in your class definition has values instead of the actual storage types that a Student object should take?

Secondly, what does your definition of your getInfo and showInfo methods return?

Those were obvious problems, but there may be more to this picture than what meets the eye...

Edit: Located another problem, in main--

int main()
{
 Student s1, s2, s3;
s2.getInfo();
s3.getInfo();
s1.showInfo();
s2.showInfo();
s3.showInfo();
 return 0;
}

How can you place Student object on the stack without giving them values first?

You have to give the appropriate arguments to your declared Student objects in main, since you never provided a definition of the default Constructor after making your own Constructor for the Student class.

-Alex

I changed the following

class Student{
public:
Student (string = "Mary", double = 100, double = 99, double = 88, int = 1);
void getInfo();
void showInfo();
private:
string name;
double test1, test2, test3;
int idNum;
};

That dropped it down to 11 errors instead of 14

All figured out here :)

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

class Student{
    public:
        Student (string = "Mary", double = 100.0, double = 99.0, double = 88.0, int = 1);
        void getInfo();
        void showInfo();
        
    private:
        string name;
        double test1, test2, test3;
        int idNum;
};

Student::Student (string n, double t1, double t2, double t3, int i){
    name = n;
    test1 = t1;
    test2 = t2;
    test3 = t3;
    idNum = i;
}

void Student::getInfo(){
    cout<<"Enter name, three tests grades and ID ";
    cin>>name>>test1>>test2>>test3>>idNum;
}
void Student::showInfo(){
    cout<<fixed<<setprecision(2)<<name<<"\t\t\t"
        <<idNum<<"\t\t\t"<<test1<<"\t\t\t"<<test2
        <<"\t\t\t"<<test3<<"\t\t\t" <<(test1*test2*test3)/3<<endl;
}

int main(){
    Student s1;
    Student s2;
    Student s3;
    s2.getInfo();
    s3.getInfo();
    s1.showInfo();
    s2.showInfo();
    s3.showInfo();
    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.