//class and objects in c++
//************************
#include<iostream>
using namespace std;
/* a class consist of the data and functions and mostly data in the private part of the class and
function in the public part of the class.classes are an expended version of structures.class is
a user define data type.*/
class marks // this is the class
{
private: //this is the private part of the class
int marks_p1,marks_p2,marks_p3,sum;
float average;
public: //this is the public part of the class
void in() //function in a class that enter the three marks of the subject
{
cout<<"please enter the marks of physics:";
cin>> marks_p1;
cout<<"please enter the marks of english:";
cin>> marks_p2;
cout<<"please enter the marks of computer:";
cin>> marks_p3;
}
void out() //function in a class that print the three marks of the subject on the screen
{
cout<<endl;
cout<<" the marks in physics are:"<<marks_p1<<endl;
cout<<" the marks in english are:"<<marks_p2<<endl;
cout<<" the marks in computer are:"<<marks_p3<<endl;
}
void add() //function in a class that add the all marks of the subject and calculate the sum of all subject
{
sum=marks_p1+marks_p1+marks_p1;
cout<<"the sum is:"<<sum<<endl;
}
void percent() //function in a class that calculate the percentage of all the marks
{
average=sum/3;
cout<<"the percentage is:"<<average<<endl;
}
};
int main()
{
marks m1; //making object of the class
m1.in();
m1.out(); // calling the function of the class with object
m1.add();
m1.percent();
}
No comments:
Post a Comment