This lab will exercise your understanding of some of the concepts covered in Chapter 12: virtual functions (think about compile-time and run-time binding) 1. We will be treating the PersonType object as a base class that may be inherited by multiple objects. We will treat the personType getAddress and setAddress as pure virtual because we wish to have all inherited objects to code these functions but do not need them in the base class. Using the code for person type provided in program examples do the following: a. Make the following function a pure virtual function: print . This function must remain const. b. Create the following functions as pure virtual functions: getAddress setAddress 2. For the purpose of this lab, we will create only one inherited Class: StudentType. Create the class, inherited as public from Persontype with the following properties: a. Private data members: major id gpa address (just one string address) b. Create the proper public functions to properly access and set private data members. Create a default constructor and an overloaded constructor to set ALL data member values. c. Overload the proper functions to retrieve, set, and process data members of the base class d. Create two studentType objects: One using the default constructor. Set all private and inherited data members using functions. One using the overloaded constructor, which sets all the private and inherited data members e. Print the following for the student objects: First Name Last Name Major Id GPA Address Complete as much as you can before you leave ensuring what you've completed compiles. These labs are entirely for your practice. You DO NOT have to comment these programs, however, please include your NAME as a comment in ALL code files. SUBMIT the code ( *.h and *.cpp) files and the project file (*.dev or *.cbp)
C++ Codeblocks
Below are the screenshots of code & output.


Below is the C++ code for the same. I have not put comments in code, since the instructions in question restricted me from doing so. Here, I have created two classes PersonType and StudentType as metioned in the question. All the virtual functions have been created in base class PersonType and implemented in inherited class StudentType.
The PersonType has member variables - 'Name' & 'address', which are inherited by StudentType. In StudentType class, various member variables are used; also, both the default and the overloaded constructor are implemented. Also setters and getters are implemented for accessing and setting member variables.
Finally in main function, two objects are created- one using default constructor whose member variables are then set using setter functions, and other using overloaded constructor. Both the objects are printed after creation.
#include <bits/stdc++.h>
using namespace std;
class PersonType
{
protected:
string Name,address;
public:
virtual string getAddress(){ return "";}
virtual void setAddress(string s){}
virtual void print(){}
};
class StudentType:public PersonType
{
private:
string major,id;
double gpa;
public:
StudentType(){}
StudentType(string n,string m,string i,double g,string a){
Name=n;
major=m;
id=i;
gpa=g;
address=a;
}
void setName(string s){
Name=s;
}
void setMajor(string s){
major=s;
}
void setId(string s){
id=s;
}
void setGpa(double s){
gpa=s;
}
void setAddress(string s){
address=s;
}
string getName() {
return Name;
}
string getMajor(){
return major;
}
string getId() {
return id;
}
double getGpa() {
return gpa;
}
string getAddress() {
return address;
}
string getFirstName(){
return Name.substr(0,Name.find(" "));
}
string getLastName(){
return Name.substr(Name.find(" ")+1);
}
void print(){
printf(" ______________ ______________ ________________________ ____________ _______ _________________ \n");
printf("| First Name | Last Name | Major | ID | GPA | Address |\n");
printf("|______________|______________|________________________|____________|_______|_________________|\n");
printf("| %12s | %12s | %22s | %10s | %5.2f | %15s | \n",getFirstName().c_str(),getLastName().c_str(),major.c_str(),id.c_str(),gpa,address.c_str());
printf("|______________|______________|________________________|____________|_______|_________________|\n\n");
}
};
int main()
{
StudentType s1=StudentType();
s1.setName("Tony Stark");
s1.setMajor("Computer Science");
s1.setId("UCO1555");
s1.setGpa(3.5);
s1.setAddress("New York");
s1.print();
StudentType s2=StudentType("John Wick","Information Technology","UIT2008",4.87,"California");
s2.print();
}
This lab will exercise your understanding of some of the concepts covered in Chapter 12: virtual...
This lab will exercise your understanding of some of the concepts covered in Chapter 10: classes, default constructors, overloaded constructors, arrays of classes A Roman numeral represents an integer using letters. Examples are XVII to represent 17, MCMLIII for 1953, and MMMCCCIII for 3303. By contrast, ordinary numbers such as 17 or 1953 are called Arabic numerals. The following table shows the Arabic equivalent of all the single-letter Roman numerals: M 1000 X 10 D 500 V 5 C...
Help with this coding assignment for C++! Add any comments for
better understanding.
Create a class named CupCake. It contains: • Has private instance variables 1. egg 2. butter 3. baking powder 4. sugar 5. flour 6. milk • All members must have public methods: getter() and setter(). • A constructor - a default constructor with no arguments. The constructor will initial all member variable to a default value 0. • One public pure virtual function showingredients() that returns void....
Please submit a .cpp file or upload zip if you have more than one file before the time up. No library function is allowed. ***The code must contain your name and has proper format. Create a class named CupCake. It contains: • Has private instance variables 1. egg 2. butter 3. baking powder 4. sugar 5. flour 6. milk • All members must have public methods: getter() and setter(). • A constructor - a default constructor with no arguments. The...
C++
Could you check my code, it work but professor said that
there are some mistakes(check virtual functions, prin() and others,
according assignment) .
Assignment:
My code:
#include<iostream>
#include<string>
using namespace std;
class BasicShape { //Abstract base class
protected:
double area;
private:
string name;
public:
BasicShape(double a, string n) {
area=a;
name=n;
}
void virtual calcArea()=0;//Pure Virtual Function
virtual void print() {
cout<<"Area of "<<getName()<<" is:
"<<area<<"\n";
}
string getName(){
return name;
}
};
class Circle : public...
Part 1. (60 pts) 1. Define an Address class in the file Address.h and implement the Address class in Address.cpp. a. This class should have two private data members, m_city and m_state, that are strings for storing the city name and state abbreviation for some Address b. Define and implement public getter and setter member functions for each of the two data members above. Important: since these member functions deal with objects in this case strings), ensure that your setters...
C++ Programming Assignment S Mammal Lab This lab's goal is to give you some practice using inheritance, virtual functions, pointers, dynamic memory allocation, random numbers, and polymorphism. To complete the lab implement the following steps: Create a class called Mammal. All mammals have a weight and a name, so its data should be the mammal's weight and name. Provide a default constructor that sets the mammal's weight to 0 and name to null, and another constructor that allows the weight...
1. Create an “include guard” (all lines of code required) for a file “plane.h” 2. When you look at a constructor, how can you determine if it is THE default constructor? 3. What can a “friend” function do that other non-member functions can not do? 4. class plane { int x;} ---------------- is x public or private? 5. What kind of a search first sorts the data into ascending or descending order, then splits the data in half, searches, splits,...
This Program should run in C++ In an effort to develop in-depth knowledge of base class, derived class, and operator overloading, we will expand on our in-class exercise of developing the rectangleType class and overload the following operators: +, -, *, ++, --, ==, !=, >>, and <<. Your program should contain the following features: a. Create a base class named rectangleType with following private data members: • length with double type • width with double type b. rectangleType class...
Language: C++
Create an abstract base class person.
The person class must be an abstract base class where the following functions are abstracted (to be implemented in Salesman and Warehouse): • set Position • get Position • get TotalSalary .printDetails The person class shall store the following data as either private or protected (i.e., not public; need to be accessible to the derived classes): . a person's name: std::string . a person's age: int . a person's height: float The...
In an effort to develop in-depth knowledge of base class, derived class, and operator overloading, we will expand on our in-class exercise of developing the rectangleType class and overload the following operators: +, -, *, ++, --, ==, !=, >>, and <<. Your program should contain the following features: a. Create a base class named rectangleType with following private data members: • length with double type • width with double type b. rectangleType class should contain the following functions: •...