write program Algorithm
Step 1: create a class studentpersonal declare roll no, age, name, sex in protected mode.
Step 2: Using a parameterized constructor initialize the values for all the data members.
Step 3: Create another class studentmark that is inherited from the base class and having the data members mark1, mark2, mark3, mark4 Using a parameterized constructor initialize the value for mark1,mark2,mark3,mark4.
Step 4: Create another class called studentsports and declare score as protected mode.
Step 5: Create a class studentresult and public inherited form studentmarks and studentsports
having the data members total,avg,grade..
Step 6: Calculate the total and avg and display the result.
I need code of this stamement
Answers
Answer:
#include<iostream>
using namespace std;
class studentpersonal
{protected:
int roll_no,age; char sex[5]; char name[10]; public:
studentpersonal()
{
cout<<"Enter your name :"<<endl; cin>>name;
cout<<"Enter your 4 digit roll_no :"<<endl; cin>>roll_no;
cout<<"Enter yor sex(Male ,Female,Shemale) :"<<endl; cin>>sex;
cout<<"STUDENT PERSONAL INFORMATION "<<endl;
cout<<"Your good name is :"<<name<<endl; cout<<"Your roll no is :"<<roll_no<<endl; cout<<"You are "<<sex<<endl;
cout<<"********************************"<<endl;
}
};
class studentmark:studentpersonal
{protected:
int mark1,mark2,mark3,mark4; public:
studentmark()
{cout<<"Please enter your marks between 1 to 100 ."<<endl; cout<<"Enter marks of English:"<<endl;
cin>>mark1;
cout<<"Enter marks of Oop :"<<endl; cin>>mark2;
cout<<"Enter marks of Urdu :"<<endl; cin>>mark3;
cout<<"Enter marks of Arabic :"<<endl;
cin>>mark4;
}
};
class studentsports
{protected:
int score; studentsports()
{
cout<<"Enter your sports score:"<<endl; cin>>score;
}
};
class studentresult:studentmark,studentsports
{public:
int total_marks; float average; char grade; void show()
{
cout<<"STUDENT RESULT "<<endl;
cout<<"You marks of English are :"<<mark1<<endl; cout<<"Your marks of OOP are :"<<mark2<<endl; cout<<"Your marks of Urdu are :"<<mark3<<endl; cout<<"Your marks of Arabic are :"<<mark4<<endl;
cout<<"******************************"<<endl;
}
void calcul()
{
total_marks=mark1+mark2+mark3+mark4+score; average=total_marks/5;
cout<<"Total marks are:"<<total_marks<<endl; cout<<"Average of marks are :"<<average<<endl; cout<<"***********************************"<<endl;}
void result()
{
if(average>=85)
cout<<"Your grade is A+ .";
else if(average<=85&&average>70)
cout<<"Your grade is A ";
else if(average<=70&&average>50) cout<<"Your grade is B";
else if(average<=50&&average>40) cout<<"Your grade is C ";
else if(average==40) cout<<"Your grade is D ";
else
cout<<"Your grade is F";
}
};
int main()
{studentresult s1; s1.show();
s1.calcul();
s1.result();
}
Explanation:
important note:
Still i'm not sure about parameterized constructor