Question

1) This exercise is about Inheritance (IS-A) Relationship. A) First, draw the UML diagram for class...

1) This exercise is about Inheritance (IS-A) Relationship.

A) First, draw the UML diagram for class Student and class ComputerSystemsStudent which are described below. Make sure to show all the members (member variables and member functions) of the classes on your UML diagram.

Save your UML diagram and also export it as a PNG.

B) Second, 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 (child) class called ComputerSystemsStudent that inherits from class Student. In addition to what is inherited from class Student, class ComputerSystemsStudent has also atrack (string) as member variable. A track can take values such a "Programming", "Web Design", "Networking", etc.


c) Write a default constructor with all default parameters for both classes Student and ComputerSystemsStudent.


d) Write printInfo() function for both classs Student and class ComputerSystemsStudent. -- For full credit, class ComputerSystemsStudent class must override the printInfo of the base class Student.


e) Create a test program that includes an object of class Student and another object of class  ComputerSystemsStudent. Write test code print the information (name, if, track) of each object.

Save your .h and .cpp files in a folder and zip the entire folder for submission. Note that you need submit a total of five files for this part.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<string>
class Student{
   private:
       std::string name;
       int id;
   public:
       Student();
       Student(std::string name,int id);
       virtual void printInfo();

};

#include "student.h"
using namespace std;
Student::Student(){
   name="";
   id=0;
}
Student::Student(std::string name,int id){
   this->name=name;
   this->id=id;
}
void Student::printInfo(){
   cout<<"Name:"<<name<<endl<<"ID:"<<id<<endl;
}

#include<iostream>
#include<string>
class ComputerSystemsStudent : public Student{
   private:
       std::string track;
   public:
       ComputerSystemsStudent();
       ComputerSystemsStudent(std::string name,int id,std::string track);
       virtual void printInfo();
};

#include "ComputerSystemsStudent.h"
using namespace std;
ComputerSystemsStudent::ComputerSystemsStudent():Student(){
   track="";
}
ComputerSystemsStudent::ComputerSystemsStudent(std::string name,int id,std::string track):Student(name,id){
   this->track=track;
}
void ComputerSystemsStudent::printInfo(){
   Student::printInfo();
   cout<<"Track:"<<track<<endl;
}

#include<iostream>
#include "Student.cpp"
#include "ComputerSystemsStudent.cpp"
using namespace std;
int main(){
   Student *std;
   ComputerSystemsStudent cs("rolly",123,"programming");
   std=&cs;
   std->printInfo();//calling child class
   return 0;
  
};

UML:

Add a comment
Know the answer?
Add Answer to:
1) This exercise is about Inheritance (IS-A) Relationship. A) First, draw the UML diagram for class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a class hierarchy to be used in a university setting. The classes are as follows:...

    Create a class hierarchy to be used in a university setting. The classes are as follows: The base class is Person. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The class should also have a static data member called nextID which is used to assign an ID number to each object created (personID). All data members must be private. Create the following member functions: o Accessor functions to allow access to first name and last name...

  • What this Lab Is About: Given a UML diagram, learn to design a class Learn how...

    What this Lab Is About: Given a UML diagram, learn to design a class Learn how to define constructor, accessor, mutator and toStringOmethods, etc Learn how to create an object and call an instance method. Coding Guidelines for All ments You will be graded on this Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc) Keep identifiers to a reasonably short length. Use upper case for constants. Use title case (first letter is u case)...

  • Create a class named Game using the following UML class diagram. GAME -gameName : string +Game()...

    Create a class named Game using the following UML class diagram. GAME -gameName : string +Game() +setGameName(in name : string) : void +getGameName() : string +displayMessage() : void This class has 2 member variables namely playerName and playerScore. The class contain following member functions: Constructor, set function, get functions, display function. Code write in 3 files: Game.h header file, funtion.cpp file and main.cpp file. The output should be: Player John has scored 50 points.

  • UML Class Diagram with Inheritance Objectives Use UML Correctly indicate inheritance Demonstrate permissions Understand inheritance relationships...

    UML Class Diagram with Inheritance Objectives Use UML Correctly indicate inheritance Demonstrate permissions Understand inheritance relationships Labwork Please read all of the directions carefully. You will create a UML class diagram reflecting the class hierarchy for a fictional program that manages university personnel as constructed according to the graph displayed below. You will need to think about the attributes and behaviors that are unique to each class, and also those attributes and behaviors that are common amongst the subclasses and...

  • Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance...

    Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...

  • a c++ program (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person...

    a c++ program (The Person, Student, Employee, Faculty, and Staff classes) Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. Use the MyDate classto create an object for date hired. A faculty...

  • Answer the following: 1.        Create a Class Car with the following instance variables: model (String), Brand...

    Answer the following: 1.        Create a Class Car with the following instance variables: model (String), Brand (String), maxspeed (double) Note: use encapsulation (all variables are private). (3 Marks) 2.        Create a non-default constructor for Class Car which takes 3 parameters. (2 Marks) 3.        Create a get and set methods for instance variable model variable only. (2 Marks) 4.        Create PrintInfo() method which prints all three instance variables. (2 Marks) 5.        Create a subclass GasCar with instance variable TankSize (double).. (2...

  • Student.h Student.cpp Person.h Person.cpp In this assignment, you need to create a class to keep track...

    Student.h Student.cpp Person.h Person.cpp In this assignment, you need to create a class to keep track of books borrowed bya student. Each book has a name, Student (who borrowed it), and the date that was borrowed (see the .h file below). Use also need to use the Person class and the Student class included in the folder. Student class inherits from the Person class as was shown in the classroom Create a Date class (in the same project of the...

  • Create a UML diagram to help design the class described in exercise 3 below. Do this...

    Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two constructors:...

  • Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram)

    Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT