c++ Programing language code Design a class1 Address Attribute private streetNum
ID: 3710068 • Letter: C
Question
c++ Programing language code
Design a class1 Address
Attribute
private streetNumber;
Public:
Overloaded constructor à set streetNum by a value passed from the user
showStreetNum();
Design class2 Student
Attributes
(Name, age, and GPA) (public, protected, and private)
public: addressPtr POINTER to Address object;
Public: showStudentInfo(): show all student’s info including the street number
Default constructor à set all attribute values with initial values
{addressPtr = new Address; addressPtr->streetNumber = 0;}
Overloaded constructor à set all attribute values by a value passed from the user
{addressPtr = new Address; addressPtr->streetNumber = ???;}
Main()è
Create a pointer to a Student object (stObjPtr) using the overloaded constructor;
Pass the pointer stObjPtru to a function printAddress(stObjPtru) that will print only the student’s name and the street number
Use/call the function showStudentInfo() to show the student’s information.
Explanation / Answer
#include<iostream>
using namespace std;
class Address
{
public:
int streetno:
Address(int streetno)
{
this->streetno=streetno;
}
void showStreetNo()
{
cout<<"the streetno is "<<this->streetno<<endl;
}
};
class Student
{
public:
string name;
Address* address;
protected:
int age;
private:
double GPA;
public Student()
{
this->name=" ";
this->age=0;
this->address=new Address(0);
}
public Student(int age, string name, Address* address)
{
this->age = age;
this->name = name;
this->address = address;
}
public Student(int name, string age, Address* address)
{
this->age = age;
this->name = name;
this->address = address;
}
public Student(Address* address,int age, string name)
{
this->age = age;
this->name = name;
this->address = address;
}
public void showStudentInfo()
{
cout<<" student name "<<this->name<<endl;
cout<<"student age"<<this->age<<endl;
cout<<"gpa is "<<this->GPA<<endl;
cout<<"student address is "<<address->streetno;
}
public void printStuaddress()
{
cout<<"student name is "<<this->name<<endl;
cout<<"the student street no is "<<address->streetno<<endl;
}
};
int main()
{
Address a=Address(123);
Student student=Student("koti",21,a);
student.showStudentInfo();
student.printStuaddress();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.