0% found this document useful (0 votes)
15 views

Week 8 Assignment

Uploaded by

iirwed79
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Week 8 Assignment

Uploaded by

iirwed79
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

// Write a program to apply inheritance using classes?

#include <iostream>

using namespace std;

class Base
{
protected:
int a, b;
public:
void setData(int a11, int b11)
{
a = a11;
b = b11;
}
int getDataA()
{
return a;

}
int getDataB() {
return b;
}
};

class Derived : public Base


{
int c;
public:
Derived()
{
}
Derived(int a11, int b11)
{
setData(a11, b11);
}
int Addition() {
c = getDataA() + getDataB();

return c;
}
};
int main() {

Derived a(10,20);
cout<<a.Addition();
}

// Write a program to print all the data about the person using inheritance
and classes in C++?

#include <iostream>
#include <cstring>
using namespace std;

class Person
{
protected:
long id;
string name;
public:
Person(){}
Person(int ID, string Name)
{
setdata(ID, Name);
}
void setdata(long ID, string Name)
{
id = ID;
name = Name;
}
long getId() { return id; }
string getName() { return name; }

};

class Sport
{
protected:
int sp;
public:
int getSp()
{
return sp;
}
void setSp(int SP)
{
sp = SP;
}

};

class Grade : public Person


{
protected:
int m1, m2, q, final;
public:
void setData(int M1, int M2, int Q, int Final)
{
m1 = M1;
m2 = M2;
q = Q;
final = Final;
}
void printData()
{
cout << "Name : " << name << endl;
cout << "ID : " << id << endl;
cout << "Subject1 : " << m1 << endl;
cout << "Subject2 : " << m2 << endl;
cout << "Quiz : " << q << endl;
cout << "Final : " << final << endl;
}

};
class Student : public Grade, public Sport
{
public:
Student() {}
Student(long ID, string Name, int M1, int M2, int Q, int Final, int Sp)
{
setdata(ID, Name);
setSp( Sp);
setData(M1, M2, Q, Final);
}
void Result()
{
printData();

cout << "Sp :" << sp << endl;


}

};

int main() {

Student a(584, "Raed", 59, 99, 1, 32,79);


a.Result();
}

You might also like