107 297
Assignments Done
97.8%
Successfully Done
In March 2023

# Answer to Question #212510 in Electrical Engineering for Amir

Question #212510

attributes name, for person name, as a character array of size 50 and age, for a

person’s age as a positive integer.

1
2021-07-02T16:40:01-0400
#include<iostream>
using namespace std;

class Person//class person
{
private:
char name[50];
int age;
public://constructor
Person()
{
name[50]={};
age=0;
}
Person(char n[50],int a)
{

for(int i=0;i<50;i++)
{
name[i]=n[i];
}
age=a;
}

void Get_Data(char n[50],int a)//setter function
{

for(int i=0;i<50;i++)
{
name[i]=n[i];
}
age=a;
}
void show_Data()//showing value
{

cout<<"Name: "<<name;
cout<<"\nAge: "<<age<<"\n";

}
};
class Student : public Person{//inheritance
private:
char degree[50];
double gpa;
public:
Student():Person()//calling constructor
{
degree[50]={};
gpa=0;

}
Student(char n[50],int age,char deg[50],double point):Person(n,age)//argument constructor
{

for(int i=0;i<50;i++)
{
degree[i]=deg[i];
}
gpa=point;
//Person(n,age);
}
void Get_Data(char n[50],int a,char deg[50],double points)
{
Person::Get_Data(n,a);
for(int i=0;i<50;i++)
{
degree[i]=deg[i];
}
gpa=points;

}
void show_Data()//showing value
{
Person::show_Data();

cout<<"Degree: "<<degree<<"\n";
cout<<"Gpa: "<<gpa<<"\n";

}

};
int main()
{
Student s1("shreya",21,"B.tech",3.8);//object of student
s1.show_Data();
}

Output:

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!