Question

In: Computer Science

HW 8-1a   1.)   Referring to the UML class diagram, create a program that utilizes the Student...

HW 8-1a  

1.)   Referring to the UML class diagram, create a program that utilizes the Student class.

- id : Integer

- units : Integer

- name : String

+ Student ( ) :

+ Student (id : Int, name : String, units : Int) :

+ ~Student( ) :

+ setID(id : Integer) : void

+ setName(name: String) : void

+ setUnits(units : Integer ) : void

+ displayRecord() : void

2.)   Include 3 files:

-   Source.cpp

-   Student.h

-   Student.cpp

3.)   In main(), declare two objects of Student type, named s1 and s2.

  • The s1 object calls the default constructor.
    • For s1, the object should be instantiated (initialized) with these values:
      • ID: 0
      • Name: (empty string)
      • Units: 0
  • The s2 object calls the overloaded constructor.
    • For s2, the object should be instantiated (initialized) with these values:
      • ID: 100
      • Name: Tom P. Lee
      • Units: 12

4.)   In main(), the s1 object calls its displayRecord() function. Here is the output:

           ID:        0

          Name:

           Units:     0

5.)   Then in main(), the s2 object calls its displayRecord() function. Here is the output:

           ID:        100

           Name: Tom P. Lee

           Units:     12

6.)   Then in main(), use the set functions to set to assign these values to the s1 object:

           ID:        101

           Name: John Lee Hooker

           Units:     15   

7.)    Finally, the s1 object calls its displayRecord() function again. Here is the output:

           ID:        100

           Name: John Lee Hooker

           Units:     15

/* OUTPUT

Here is student #1:

   ID:     0

   Name:  

   Units: 0

Here is student #2:

   ID:     100

   Name:   Tom P. Lee

   Units: 12

Here is student #1 after the set functions:

   ID:     100

   Name:   John Lee Hooker

   Units: 15

1) Referring to the following UML class diagram, create a program that utilizes three class specifications:

Student, UnderGrad, and Grad

- Include these 7 files in your project:

- main.cpp

- Student.h

- Student. cpp

- UnderGrad.h

- UnderGrad.cpp

- Grad.h

- Grad.cpp

2.)   In main(), declare two objects of UnderGrad and Grad type, respectively, as show below:

int main()

{

           UnderGrad underGrad(100, 9, "Tom Lee", "Freshman");

           Grad grad(101, 12, "Jim Jones", "PHD");

3.)   In main(), the object, underGrad, calls its displayRecord() function. Here is the output:

           ID:        100

           Name: Tom Lee

           Units:     9

           Class:     Freshman

4.)   In main(), the object, grad, calls its displayRecord() function. Here is the output

             of the function:

           ID:        101

           Name: Jim Jones

           Units:     12

           Degree:    PHD

5.)   Then, in main(), the object, grad, calls its setUnits() function, and changes the number of units

from 12 to 15.

6.)   Finally, in main(),the object, grad, calls its displayRecord() function. Here is the output

             of the function:

           ID:        101

           Name: Jim Jones

           Units:     15              ß (Units has changed to 15)

          Degree:    PHD

Please make a code on C++ language, and please add comments for each codes.

Solutions

Expert Solution

1.

// Student.h
#ifndef STUDENT_H
#define STUDENT_H

#include <string>
using namespace std;

class Student
{
private:
int id;
int units;
string name;
public:
Student();
Student(int id, string name, int units);
~Student();
void setID(int id);
void setName(string name);
void setUnits(int units);
void displayRecord();
};

#endif

//end of Student.h

// Student.cpp

#include "Student.h"
#include <iostream>

// default constuctor to initialize the fields to default values
Student::Student() : id(0), units(0), name("")
{}

// parameterized constuctor to initialize the fields to specified values
Student::Student(int id, string name, int units) : id(id), units(units), name(name)
{}

// destructor to destroy the Student object
Student::~Student()
{}

// function to set the id
void Student::setID(int id)
{
this->id = id;
}

// function to set the name
void Student::setName(string name)
{
this->name = name;
}

// function to set the units
void Student::setUnits(int units)
{
this->units = units;
}

// function to display student information
void Student::displayRecord()
{
cout<<"ID: "<<id<<endl;
cout<<"Name: "<<name<<endl;
cout<<"Units: "<<units<<endl;
}

//end of Student.cpp

// main.cpp
#include "Student.h"
#include <iostream>
using namespace std;

int main()
{
Student s1;
cout<<"Here is student #1:"<<endl;
s1.displayRecord();

Student s2(100, "Tom P. Lee",12);
cout<<"Here is student #2:"<<endl;
s2.displayRecord();
cout<<"Here is student #1 after the set functions:"<<endl;
s1.setID(101);
s1.setName("John Lee Hooker");
s1.setUnits(15);
s1.displayRecord();
return 0;
}

//end of main.cpp

Output:


Related Solutions

For this assignment, create a complete UML class diagram of this program. You can use Lucidchart...
For this assignment, create a complete UML class diagram of this program. You can use Lucidchart or another diagramming tool. If you can’t find a diagramming tool, you can hand draw the diagram but make sure it is legible. Points to remember: • Include all classes on your diagram. There are nine of them. • Include all the properties and methods on your diagram. • Include the access modifiers on the diagram. + for public, - for private, ~ for...
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram...
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram which shows: Classes (Only the ones listed in bold below) Attributes in classes (remember to indicate privacy level, and type) No need to write methods Relationships between classes (has is, is a, ...) Use a program like Lucid Cart and then upload your diagram. Each movie has: name, description, length, list of actors, list of prequals and sequals Each TV Show has: name, description,...
Follow the UML diagram and directions on the attached file to create a RectangularPrism class and...
Follow the UML diagram and directions on the attached file to create a RectangularPrism class and a RectangularPrismDemo class. --------------------------------------------------------------------------------------------------------------------------------------- RectangularPrism            - length: double       - width: double       - height: double + RectangularPrism() + RectangularPrism(l:double,w:double, h:double) + setLength(l:double):void + setWidth(w:double):void + setHeight(h:double):void +getLength():double +getWidth():double +getHeight():double +getVolume():double +getSurfaceArea():double +toString():String --------------------------------------------------------------------------------------------------------------------- Create a RectangularPrism class in its own file based on the UML Create a separate RectangularPrismDemo Class file to demonstrate your class by doing the following: Create two prisms,...
In java program format Submit your completed UML class diagram and Java file. Part I: Create...
In java program format Submit your completed UML class diagram and Java file. Part I: Create a UML diagram for this assignment PartII: Create a program that implements a class called  Dog that contains instance data that represent the dog's name and age.   define the Dog constructor to accept and initialize instance data.   create a method to compute and return the age of the dog in "person-years" (note: dog age in person-years is seven times a dog's age).   Include a toString...
In java program format Submit your completed UML class diagram and Java file. Part I: Create...
In java program format Submit your completed UML class diagram and Java file. Part I: Create a UML diagram for this assignment PartII: Create a program that implements a class called Dog that contains instance data that represent the dog's name and age. define the Dog constructor to accept and initialize instance data. create a method to compute and return the age of the dog in "person-years" (note: dog age in person-years is seven times a dog's age). Include a...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This...
C++ HW Aim of the assignment is to write classes. Create a class called Student. This class should contain information of a single student. last name, first name, credits, gpa, date of birth, matriculation date, ** you need accessor and mutator functions. You need a constructor that initializes a student by accepting all parameters. You need a default constructor that initializes everything to default values. write the entire program.
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {...
Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {       public int month;    public int day;    public int year;    public Date(int month, int day, int year) {    this.month = month;    this.day = day;    this.year = year;    }       public Date() {    this.month = 0;    this.day = 0;    this.year = 0;    } } //end of Date.java // Name.java public class Name...
1.) According to the UML Class Diagram, these are the mutator and accessor methods that you...
1.) According to the UML Class Diagram, these are the mutator and accessor methods that you need to define: 1a.) +setName(value:String):void 1b.) +setGPA(value:double):void 1c.) +setID(value: String):void 1d.) +getName(): String 1e.) +getLastName():String 2.) Working with constructors 2a.) +Student() : This is the default constuctor. For the Strings properties, initialize them to null. The order is String ID, String name, String lastName, and double GPA. 2b.) +Student(value:String) - This constructor receives just the ID. 2c.) +Student(value:String, var: String) - This constructor receives...
Create a UML Class Diagram of a Food Supermarket. Show inheritance of common methods. Upload image.
Create a UML Class Diagram of a Food Supermarket. Show inheritance of common methods. Upload image.
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in...
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in Java. Circle Circle Radius: double Circle() Circle(newRadius: double) getArea(): double setRadius(newRadius: double): void getRadius(): double After creating the Circle class, you should test this class from the main() method by passing objects of this class to a method “ public static void printAreas(Circle c, int times)” You should display the area of the circle object 5 times with different radii.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT