Skip to content

Instantly share code, notes, and snippets.

@sprintr
Created June 14, 2013 05:40
Show Gist options
  • Select an option

  • Save sprintr/5779698 to your computer and use it in GitHub Desktop.

Select an option

Save sprintr/5779698 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class Student
{
public:
void getData() {
cout << "Enter your roll number: " << endl;
cin >> rollNo;
cout << "Enter your full name: " << endl;
cin >> name;
}
private:
int rollNo;
string name;
};
class Marks : public Student
{
public:
void getMarks() {
cout << "Enter your marks of 1st Subject: " << endl;
cin >> m1;
cout << "Enter your marks of 2nd Subject: " << endl;
cin >> m2;
cout << "Enter your marks of 3rd Subject: " << endl;
cin >> m3;
}
void display() {
percentage = ((m1 + m2 + m3) / 300.0) * 100.0;
cout << "Your percentage is: " << percentage << endl;
}
private:
int m1, m2, m3;
double percentage;
};
int main()
{
Marks s1;
s1.getData();
s1.getMarks();
s1.display();
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment