This is my code

class AddResult
{
private:
string ar_stu_id, ar_mod1, ar_mod2, ar_mod3, ar_mark1, ar_mark2, ar_mark3;
public:
void addresult();
    AddResult(string, string, string, string, string, string, string)
{
    cout<<ar_stu_id <<" " << ar_mod1 <<" " << ar_mod2 <<" " << ar_mod3 <<" " << ar_mark1 <<" " << ar_mark2 <<" " << ar_mark3;
}
~AddResult()
{
    cout<<"Complete!"<<endl<<endl;
}
};
void AddResult::addresult()
{
system("cls");
char con;

ofstream stu_mark;
cout<<"Please insert the following information.\n\n";
stu_mark.open ("StudentMarks.txt", fstream::in | fstream::out | fstream::ate | ios::app); 

cout<<"Student ID\n";
getline(cin, ar_stu_id);
cout<<"Module 1"<<endl;
getline(cin, ar_mod1);
cout<<"Mark 1"<<endl;
getline(cin, ar_mark1);
cout<<"Module 2"<<endl;
getline(cin, ar_mod2);
cout<<"Mark 2"<<endl;
getline(cin, ar_mark2);
cout<<"Module 3"<<endl;
getline(cin, ar_mod3);
cout<<"Mark 3"<<endl;
getline(cin, ar_mark3);

{
    AddResult(ar_stu_id, ar_mod1, ar_mod2, ar_mod3, ar_mark1, ar_mark2, ar_mark3);
}

stu_mark << ar_stu_id << "    ";
stu_mark << ar_mod1 << "       ";
stu_mark << ar_mark1;
stu_mark << "         " << ar_mod2 << "       ";
stu_mark << ar_mark2;
stu_mark << "        " << ar_mod3 << "      ";
stu_mark << ar_mark3 << endl;
stu_mark.close();

cout<<"Continue? (Y/N)";
cin>>con;
if(con=='y')
{
    system("cls");
    AddResult obj; <----no default constructor in Class AddResult
    obj.addresult();
}
else if (con=='n')
{
    Admin obj;
    obj.works();
}
}

Anyone can help me?

Recommended Answers

All 2 Replies

Automagic synthesis of a default constructor is disabled when you provide any explicit constructor. If that explicit constructor has arguments and not all of them are defaulted, then your class will not support a default constructor unless you explicitly define one.

Your class has a seven argument constructor, so the default construction syntax won't work. There are quite a few problems with your code, but that's the exact cause of the error you're receiving.

If you describe what the program is supposed to be doing, I may be able to help you redesign things to work better.

actually im doing the assignment and this code just part of my program.
i wan to display the variable that i enter, thats my problem now.

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.