In: Computer Science
Write a C++ program that will be an information system for
Oregon State University using classes as well as demonstrating a
basic understanding of inheritance and polymorphism.
You will create a representation of an Oregon State University
information system that will contain information about the
university. The university will contain a name of the university, n
number of buildings, and m number of people. People can be either a
student or an instructor. Every person will have a name and an age.
Every student will have also have a GPA, but an instructor will NOT
have a GPA. Every instructor will have an instructor rating, but a
student will NOT have an instructor rating. Every building will
have a name, the size in sqft (preferred the real value which you
need to look up), and an address (stored as a string, also
preferred to look this up).
People will contain a method called “do_work” that will take in a
random integer as a parameter that represents how many hours they
will do work for. If the person is a student, a message will be
printed to the screen that says “PERSON_NAME did X hours of
homework.” If the person is an instructor, a message will be
printed to the screen that says “Instructor PERSON_NAME graded
papers for X hours.” You will need to fill in the appropriate
values.
The student GPA can either be an input from the user or randomized,
but it must be between 0.0 and 4.0. It cannot be preset. The
instructor rating can either be an input from the user or
randomized, but it must be between 0.0 and 5.0. The ages of a
person can be randomized or an input, but make it realistic. You
can choose whether it is randomized or user input, or both.
The university will contain a method that will print the name and
address of all the buildings in its information system and another
method that will print the name of all the people. The name of the
university MUST be “Oregon State University” (because we are the
best).
You will manually instantiate at least 1 student, 1 instructor, and
2 buildings, then give them values and store them appropriately in
the university object. You can do this in whatever fashion you
wish.
You will have a menu that does at least the following:
1) Prints names of all the buildings
2) Prints names of everybody at the university
3) Choose a person to do work
4) Exit the program
Note that option 3 will require you to print another menu that
gives options for each person.
You may create any other functions, methods, member variables, etc.
to modularize your code and complete the lab.
You may use vectors for this assignment if you so choose.
(10 pts) Program Style/Comments
In your implementation, make sure that you include a program header
in your program, in addition to proper indentation/spacing and
other comments! Make sure you review the style guidelines for this
class, and begin trying to follow them, i.e. don’t align everything
on the left or put everything on one line! Also view the “Things
not to do in the code” page and the “Things you need to do in your
code” page as you will be held to these.
Add an option to save the information system to a file, and add an option to read a saved information system from a file so that you can close the program, but not lose information. This will also require you to be able to add people and/or buildings to the program during runtime. This is an all or nothing extra credit (you will not get partial points for partial completion).
Screenshot of code:
Screenshot of output:
Code to copy:
#include "stdafx.h" // use only if using visual studio
#include<iostream>
#include<stdlib.h>
#include<string>
#include<math.h>
using namespace std;
//Class university is declared
class university
{
public:
//Data members declared
string nameUniv;
int numberBuild, numberPeople;
string buildName, address;
string sname[10], instructorname[10];
int size, age[10], instage[10];
float GPA[10], rating[10];
//Constructor is defined
university()
{
nameUniv = "Oregon State University";
numberBuild = 5;//n number of buildings
numberPeople = 10;//m number of peoples
}
//Method is defined to get the name of the students
void getStudentName()
{
const int LOW = 0.0;
const int HIGH = 4.0;
const int LOW1 = 15;
const int H1 = 25;
srand(3);
sname[0] = "jack mark"; age[0] = rand() % (H1 - LOW1 + 1) +
LOW1;
GPA[0] = rand() % (HIGH - LOW + 1) + LOW;
sname[1] = "john rock"; age[1] = rand() % (H1 - LOW1 + 1) +
LOW1;
GPA[1] = rand() % (HIGH - LOW + 1) + LOW;
sname[2] = "Peter Adams"; age[2] = rand() % (H1 - LOW1 + 1) +
LOW1;
GPA[2] = rand() % (HIGH - LOW + 1) + LOW;
sname[3] = "Ricky Ponting"; age[3] = rand() % (H1 - LOW1 + 1) +
LOW1;
GPA[3] = rand() % (HIGH - LOW + 1) + LOW;
sname[4] = "Methew Haden"; age[4] = rand() % (H1 - LOW1 + 1) +
LOW1;
GPA[4] = rand() % (HIGH - LOW + 1) + LOW;
sname[5] = "Jovial Chahal"; age[5] = rand() % (H1 - LOW1 + 1) +
LOW1;
GPA[5] = rand() % (HIGH - LOW + 1) + LOW;
}
//Method is defined to get the name of the instructors
void getInstructorname()
{
const int LOW = 0.0;
const int HIGH1 = 5.0;
const int LOW1 = 28;
const int H1 = 70;
srand(3);
instructorname[0] = "Isabel Garvin"; instage[0] = rand() % (H1 -
LOW1 + 1) + LOW1;
rating[0] = rand() % (HIGH1 - LOW + 1) + LOW;
instructorname[1] = "Peter Adams"; instage[1] = rand() % (H1 - LOW1
+ 1) + LOW1;
rating[1] = rand() % (HIGH1 - LOW + 1) + LOW;
instructorname[2] = "Adam Gilchrist"; instage[2] = rand() % (H1 -
LOW1 + 1) + LOW1;
rating[2] = rand() % (HIGH1 - LOW + 1) + LOW;
instructorname[3] = "Serena Villiams"; instage[3] = rand() % (H1 -
LOW1 + 1) + LOW1;
rating[3] = rand() % (HIGH1 - LOW + 1) + LOW;
instructorname[4] = "Maria Sharapoa"; instage[4] = rand() % (H1 -
LOW1 + 1) + LOW1;
rating[4] = rand() % (HIGH1 - LOW + 1) + LOW;
}
//Method to print the building details
void printBuild(university U[])
{
cout << "\n--- Names of buildings ---\n";
for (int i = 0; i < numberBuild; i++)
{
cout << "Building name:\t" << U[i].buildName <<
"\n";
cout << "Address:\t" << U[i].address <<
"\n";
}
}
//Method to print the name of the students
void printStudentName()
{
cout << "\n--- Name of Students ---\n";
for (int i = 0; i < 6; i++)
cout << "\nName : " << sname[i] << "\tAge : "
<< age[i] << "\tGrades : " << GPA[i];
}
//Method to print the name of the instructors
void printInstructorName()
{
cout << "\n--- Name of Instructors ---\n";
for (int i = 0; i < 5; i++)
cout << "\nName : " << instructorname[i] <<
"\tAge : " << instage[i] << "Ratings : " <<
rating[i];
}
};
class people : university
{
public:
//Declare the data members
string peopleName;
const int LOW1 = 1;
const int H1 = 8;
int age, hours[20];
float GPA;
float rating;
//Define the method do_work to check out the working hours of
instructor and student
void do_work(people P[], char p)
{
university u;
//Prints the working hour of student
if (p == 'S')
for (int i = 0; i < 6; i++)
{
hours[i] = rand() % (H1 - LOW1 + 1) + LOW1;
cout << "Student " <<university::sname[i] << "
did " << hours[i] << " of homework\n";
}
else
//Prints the working hours of instructor
for (int i = 0; i < 5; i++)
{
hours[i] = rand() % (H1 - LOW1 + 1) + LOW1;
cout << " Instructor " << instructorname[i] << "
graded papers for" << hours[i] << ".\n";
}
}
};
//start the main function
int main()
{
//Declare variables
int op;
char ch;
university U[10], U1;
char person;
people P[5], p1;
U1.getStudentName();
U1.getInstructorname();
U[0].buildName = " AB 6 Small Shed-Berry Creek ";
U[1].buildName = "AB Adair Hay Store-Loaf S";
U[2].buildName = "Apiary (Bee) Building";
U[3].buildName = "Animal Physiology Lab";
U[4].buildName = "AS Adair Barn #2-Soap CR";
U[0].address = "27280 TAMPICO RD, CORVALLIS, OR 97330 ";
U[1].address = "28120 BEEF BARN RD,CORVALLIS, OR 97330";
U[2].address = "681 SW 26TH STREET CORVALLIS, OR 97331";
U[3].address = "3550 CAMPUS WAY CORVALLIS, OR 97330";
U[4].address = "2750 SW CAMPUS WAY CORVALLIS, OR 97331";
do
{
cout << "\n\t\t" << U1.nameUniv << "\n";
cout << "\n\t1) Prints names of all the buildings";
cout << "\n\t2) Prints names of everybody at the
university";
cout << "\n\t3) Choose a person to do work";
cout << " \n\t4) Exit the program \n choose option : ";
cin >> op;
switch (op)
{
case 1: U1.printBuild(U); break;
case 2: cout << "\n Choose 1) To print students name:
";
cout << "\n Choose 2) for instructors name: ";
cin >> person;
switch (person)
{
case '1': U1.printStudentName(); break;
case '2': U1.printInstructorName(); break;
default: cout << "\nWrong Input"; break;
}
break;
case 3: cout << "\n\tChoose S) student \n\tI)Instructor : ";
cin >> person;
switch (person)
{
case 'S': p1.do_work(P, person); break;
case 'I': p1.do_work(P, person); break;
default: cout << "\nWrong Input"; break;
}
break;
case 4: exit(1);
}
cout << "\nDo you want to continue ? y/n : ";
cin >> ch;
} while (ch == 'y');
system("pause");// use only if using visual studio
return 0;
}