I tried to call the function print and it worked.The function newsucc the only one who had this problem. I tried to rename it, and made the function at class national like this virtual void newsucc(int students, int succ) { }; and a lot of things but nothing worked the code about an exam at our country that could national exam, we should use class and inheritance in c++ the base class is national the child class are arch and IT
#include <iostream>
#include <string>
using namespace std;
class National {
protected:
string name;
int students;
int succ;
public:
National()
{
name = "";
students = 0;
succ = 0;
}
National(string ex, int s, int su)
{
name = ex;
students = s;
succ = su;
}
National(National&N ) {
this->name = N.name;
this->students = N.students;
this->succ = N.succ;
}
void print()
{
cout << "The results of the National Exam" << endl;
}
virtual void newsucc() { };
~National()
{
cout << "The End" << endl;
}
};
class arch : public National {
public:
arch(int _students, int _succ) :National("architecture engineering", _students, _succ)
{
}
~arch()
{
}
void print() {
cout << "The National Exam's result of the architecture engineering is" << endl;
}
void newsucc(int _students,int _succ)
{
cout << "The number of the Successful students" << (_students*_succ)/100 << endl;
}
};
class IT : public National
{
public:
IT (int _students, int _succ) : National("IT engineering", _students, _succ)
{
}
~IT()
{
}
void print() {
cout << "The National Exam's result of the IT engineering" << endl;
}
void newsucc(int _students,int _succ)
{
cout << "The number of the Successful students" << (_students*_succ)/100 << endl;
}
};
int main()
{
cout << "-----------------------------------" << endl;
arch obj2 (300,65);
obj2.newsucc();
cout << "-----------------------------------" << endl;
IT obj3 (500,40);
obj3.newsucc();
}
Aucun commentaire:
Enregistrer un commentaire