Here is the code from the previous three steps:
#include <iostream>
using namespace std;
class Student
{
private:
//class variables
int ID;
string firstName,lastName;
public:
Student(int ID,string firstName,string lastName)
//constructor
{
this->ID=ID;
this->firstName=firstName;
this->lastName=lastName;
}
int getID() //getter method
{
return ID;
}
virtual string getType() = 0; //pure virtual function
virtual void printInfo() //virtual function to print basic details
of a student
{
cout << "Student type: " << getType() <<
endl;
cout << "Student ID: " << ID << endl;
cout << "Student name: " << firstName << " "
<< lastName << endl;
}
};
class ResearchStudent : public Student //class ResearchStudent
inherits class Student
{
private:
//class variables
string supervisor,thesis;
public:
//constructor
ResearchStudent(int ID,string firstName,string lastName,string
supervisor,string thesis): Student(ID,firstName,lastName)
{
this->supervisor=supervisor;
this->thesis=thesis;
}
void printInfo() //method to print the additional details of a
student
{
Student::printInfo();
cout << "Supervisor name: " << supervisor <<
endl;
cout << "Thesis name: " << thesis << endl;
}
string getType() //method to get student type
{
return "Research Student";
}
};
class TaughtStudent : public Student //class taughtStudent inherits
class Student
{
private:
string modules[10];
int numRegisteredModules;
public:
TaughtStudent(int ID,string firstName,string lastName):
Student(ID,firstName,lastName) //constructor
{
numRegisteredModules=0;
}
void printInfo() //method to print the additional details of a
student
{
Student::printInfo();
cout << "Modules: " << endl;
for(int i=0;i<numRegisteredModules;i++)
cout << modules[i] << endl;
}
bool registerFor(const string &moduleName) //function to add an
additional module
{
if(numRegisteredModules==10)
return false;
modules[numRegisteredModules]=moduleName;
numRegisteredModules++;
return true;
}
string getType() //method to get student type
{
return "Taught Student";
}
};
int main() //main method to test the functions
{
ResearchStudent r(101,"Debjit","Ganguli","Debayan
Ganguly","AI");
r.printInfo();
TaughtStudent t(102,"Indrajit","Ghosh");
t.registerFor("AI");
t.registerFor("ML");
t.printInfo();
return 0;
}
Note: Could you plz go this code and let me know if
u need any changes in this.Thank You
_________________
#include <iostream>
using namespace std;
class Student
{
private:
//class variables
int ID;
string firstName,lastName;
public:
Student(int ID,string firstName,string lastName)
//constructor
{
this->ID=ID;
this->firstName=firstName;
this->lastName=lastName;
}
int getID() //getter method
{
return ID;
}
virtual string getType() = 0; //pure virtual function
virtual void printInfo() //virtual function to print basic details
of a student
{
cout << "Student type: " << getType() <<
endl;
cout << "Student ID: " << ID << endl;
cout << "Student name: " << firstName << " "
<< lastName << endl;
}
};
class ResearchStudent : public Student //class ResearchStudent
inherits class Student
{
private:
//class variables
string supervisor,thesis;
public:
//constructor
ResearchStudent(int ID,string firstName,string lastName,string
supervisor,string thesis): Student(ID,firstName,lastName)
{
this->supervisor=supervisor;
this->thesis=thesis;
}
void printInfo() //method to print the additional details of a
student
{
Student::printInfo();
cout << "Supervisor name: " << supervisor <<
endl;
cout << "Thesis name: " << thesis << endl;
}
string getType() //method to get student type
{
return "Research Student";
}
};
class TaughtStudent : public Student //class taughtStudent inherits
class Student
{
private:
string modules[10];
int numRegisteredModules;
public:
TaughtStudent(int ID,string firstName,string lastName):
Student(ID,firstName,lastName) //constructor
{
numRegisteredModules=0;
}
void printInfo() //method to print the additional details of a
student
{
Student::printInfo();
cout << "Modules: " << endl;
for(int i=0;i<numRegisteredModules;i++)
cout << modules[i] << endl;
}
bool registerFor(const string &moduleName) //function to add an
additional module
{
if(numRegisteredModules==10)
return false;
modules[numRegisteredModules]=moduleName;
numRegisteredModules++;
return true;
}
string getType() //method to get student type
{
return "Taught Student";
}
};
void studentTester();
int main() //main method to test the functions
{
ResearchStudent r(101,"Debjit","Ganguli","Debayan
Ganguly","AI");
r.printInfo();
TaughtStudent t(102,"Indrajit","Ghosh");
t.registerFor("AI");
t.registerFor("ML");
t.printInfo();
studentTester();
return 0;
}
void studentTester()
{
//Declaring constant
const int SIZE = 4;
TaughtStudent t1(111,"Kane","Williams");
t1.registerFor("AI");
t1.registerFor("ML");
t1.registerFor("MS");
TaughtStudent t2(112,"Sachin","Tendulkar");
t2.registerFor("ML");
t2.registerFor("MS");
t2.registerFor("AA");
ResearchStudent r1(121,"Bob","Tamer","Sanjeev Khosla","AB");
ResearchStudent r2(132,"Peter","Komb","Manish Malhotra","AI");
//Creating an array of ship pointers
Student* students[SIZE] = { &t1, &t2, &r1,
&r2};
cout<<"\n_____ Displaying Students Array
____"<<endl;
for(int i=0;i<SIZE;i++)
{
students[i]->printInfo();
}
}
_______________________
Output:
_______________Could you plz rate me well.Thank
You
Here is the code from the previous three steps: #include <iostream> using namespace std; class Student...
Answer this in c++ #include <iostream> #include <fstream> #include <string> using namespace std; class Person { public: Person() { setData("unknown-first", "unknown-last"); } Person(string first, string last) { setData(first, last); } void setData(string first, string last) { firstName = first; lastName = last; } void printData() const { cout << "\nName: " << firstName << " " << lastName << endl; } private: string firstName; string lastName; }; class Musician : public Person { public: Musician() { // TODO: set this...
//Vehicle.h #pragma once #include<iostream> #include"Warranty.h" #include<string> using namespace std; class Vehicle{ protected: string make; int year; double mpg; Warranty warranty; static int numOfVehicles; public: Vehicle(); Vehicle(string s, int y, double m, Warranty warranty); Vehicle(Vehicle& v); ~Vehicle(); string getMake(); int getYear(); double getGasMileage(); void setMake(string s); void setYear(int y); void setYear(string y); void setGasMileage(double m); void setGasMileage(string m); void displayVehicle(); static int getNumVehicles(); Warranty getWarranty(); void setWarranty(Warranty& ); }; //Vehicle.cpp #include "Vehicle.h" #include <string> Vehicle::Vehicle() { make = "unknown"; year =...
#include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string choice; string destination; public: Car() { reportingMark = ""; carNumber = 0; kind = "Others"; loaded = 0; destination = "NONE"; } ~Car() { } void setUpCar(string &reportingMark, int &carNumber, string &kind, bool &loaded, string &destination); }; void input(string &reportingMark, int &carNumber, string &kind, bool &loaded,string choice, string &destination); void output(string &reportingMark, int &carNumber,...
C++ #include <iostream> using namespace std; bool checkinventoryid(int id) { return id > 0; } bool checkinventoryprice(float price) { return price > 0; } void endProgram() { system("pause"); exit(0); } void errorID(string str) { cout << "Invalid Id!!! " << str << " should be greater than 0" << endl; } void errorPrice(string str) { cout << "Invalid Price!!!" << str << " should be greater than 0" << endl; } int inputId() {...
#code for creature.cpp #include <iostream> using namespace std; class Creature { public: Creature(); void run() const; protected: int distance; }; Creature::Creature(): distance(10) {} void Creature::run() const { cout << "running " << distance << " meters!\n"; } class Wizard : public Creature { public: Wizard(); void hover() const; private: int distFactor; }; Wizard::Wizard() : distFactor(3) {} void Wizard::hover() const { cout << "hovering " << (distFactor * distance) << " meters!\n"; } //Created new derived class from Creature class Widget...
#include <iostream> using namespace std; class Circle{ // private member variable named radius private: double radius; // get function for radius public: double getRadius(){ return radius; } // set function for radius void setRadius(double rad){ radius=rad; } // returning area = 3.14159 * radius * radius double getArea(){ return (3.14159 * radius * radius); } }; // Sample run int main() { // Declaring object of Circle Circle myCircle; myCircle.setRadius(5); // printing radius of circle cout<<"Radius of circle is: "<<(myCircle.getRadius())<<endl;...
Find Output. Just output. No explanation needed.. #include <iostream> #include <string> using namespace std; class baseClass { public: void print() const; baseClass(string s = " ", int a = 0); //Postcondition: str = s; x = a; protected: int x; private: string str; }; class derivedClass: public baseClass { public: void print() const; derivedClass(string s = "", int a = 0, int b = 0); //Postcondition: str = s; x = a; y = b; private: int y; }; int...
CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...
TOE B.2 - 30 pts class Student public Student(0 cout <<"Student0, constructor called." << endl; explicit Student string stuName): stuName(stuName) cout << "Student stuName), constructor called." << endl; -Student) cout<-Student0, destructor called." << endl; string getName) return this->stuName void sayHi0 cout<< "Student: Hi!" << endl 4 virtual void sayHello0 cout <<"Student: Hello!" << endl private string stuName "Student" 5 class CSStudent: public Student f public CSStudent0 0 explicit CSStudent string stuName) -CSStudent) Student) 0 6 cout<<"-CSStudent), destructor called."<<endl; void sayHello)...
Given the following code: #include <iostream> #include <iomanip> using namespace std; class Animal{ private: int height; int weight; public: void setHeight(int h){ height = h; } int getHeight(){ return height; } void setWeight(int w){ weight = w; } int getWeight(){ return weight; } virtual void makeSound() = 0; virtual void eat(); }; class Dog: public Animal{ public: void makeSound(){ cout << "Bow Bow\n"; } void eat (){ cout <<"The dog is eating\n"; } void Catch(){ cout << "The dog is...