Write a program that contains the following parts. Write each class interface an
ID: 3684159 • Letter: W
Question
Write a program that contains the following parts. Write each class interface and implementation, in a different .h and .cpp file, respectively. a) Create a class called "Student" that has a name (string) and ID (int) as member variables. b) Create a derived class called "ComputerSystemsStudent" from Student class. ComputerSystemsStudent has also a track (string) as member variable. A track take values such a "Programming", "Web Design", "Networking", etc. c) Write a constructor with all default parameters for Student and ComputerSystemsStudent classes. d) Write printInfo() function for Student and ComputerSystemsStudent classes. -- For ful credit, ComputerSystemsStudent class must overridde the printInfo of the Student class.
(please help to show which file is which)
Explanation / Answer
// Student.h
#ifndef STUDENT_H
#define STUDENT_H
#include <iostream>
using namespace std;
class Student{
public:
string name;
int ID;
Student(string n, int i);
void printInfo();
};
#endif
// Student.cpp
#include "Student.h"
#include <iostream>
using namespace std;
Student::Student(string n, int i){
name = n;
ID = i;
}
void Student::printInfo(){
cout << "Name : " << name << " ";
cout << "ID : " << ID << " ";
}
// ComputerSystemsStudent.h
#ifndef COMPUTER_SYSTEM_STUDENT_H
#define COMPUTER_SYSTEM_STUDENT_H
#include <iostream>
using namespace std;
class ComputerSystemsStudent: public Student{
public:
string track;
void printInfo();
ComputerSystemsStudent(string n, int i, string t);
};
#endif
// ComputerSystemsStudent.cpp
#include "ComputerSystemsStudent.h"
#include <iostream>
using namespace std;
ComputerSystemsStudent::ComputerSystemsStudent(string n, int i, string t):Student(n, i){
track = t;
}
void ComputerSystemsStudent::printInfo(){
cout << "Name : " << name << " ";
cout << "ID : " << ID << " ";
cout << "Track : " << track << " ";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.