College Information System C++ Program Help writing the following program Requir
ID: 3914895 • Letter: C
Question
College Information System C++ Program
Help writing the following program
Requirements
This program is a simple representation of an college information system that contains information about the university.
Below are the requirements for all the classes and the relationship between them.
Important: You may use vectors or arrays for this assignment if you choose so.
Note: For each class, you are required to create necessary functions such as constructors, setters, getters, destructors to make the program work.
University Class
The University class contains the following member variables:
name: name of the university.
The name of the university MUST be “State University”
buildings: contains n number of Building objects
people: contains m number of Person objects
It contains the following member functions:
A function that prints the information on all the buildings in its information system (name, address, and building’s size)
A function that prints the information of all the people (name, age, GPA or Rating)
Note: The information on Building class and Person class are described below.
Note: When printing information of all people, you need to distinguish instructors and students by print either a “GPA” or “Rating”.
Building Class
The Building class contains the following member variables:
name: name of the building
size: the size of the building (in sqft)
address: address of the building (stored as string)
Note: No additional member function required for this class.
Person Class
Person class is polymorphic, a Person pointer can hold an Instructor/Student object.
The Person class contains the following member variables:
name: name of the person
age: age of the person
The age of a person can be randomized or from input, but make it realistic
The Person class contains the following member function:
A function called “do_work()” that generates a random number that represents how many hours they will do work for, and then output message depending on if the Person is a Student or an Instructor.
Note: You can find more information on what message to output below.
Note: You can set a range for the random number to make the working hours look reasonable.
Student Class
The Student class contains the following member variable:
GPA, the student’s GPA (double or float data type)
The range for GPA must be between 0.0 and 4.0.
For “do_work()” in Person class, if the Person is a Student, then the function should output the following message:
“PERSON_NAME did X hours of homework.” Where PERSON_NAME is the person’s name, and X is the randomly generated number.
Instructor Class
The Instructor class contains the following member variable:
rating, the instructor’s rating (double or float data type)
The range for rating must be between 0.0 and 5.0.
For “do_work()” in Person class, if the Person is an Instructor, then the function should output the following message:
“PERSON_NAME graded papers for X hours.” Where PERSON_NAME is the person’s name, and X is the randomly generated number.
Menu
The menu must have at least the following options:
Prints information about all the buildings
Prints information of everybody at the university
Choose a person to do work
Exit the program
If option 3 is selected, the program should print another menu that prints all the people’s name and let the user input the choice of the person the user would like, to do work.
When the program starts, you need to manually instantiate at least 1 student, 1 instructor, and 2 buildings inside the University object. It can be done by either hard coding that information, or have the user input all the information at the start of the program.
You can add more options in the menu such as adding more Person/Buildings, or create other functions/variables to modularize code and complete the lab. It is not a hard requirement.
Explanation / Answer
#include<bits/stdc++.h>
using namespace std;
class person{
string name;
int age;
public:person(){
name="";
age=0;
}
void set_name(string n){
name=n;
}
void set_age(int a){
age=a;
}
string get_name(){
return name;
}
int get_age(){
return age;
}
};
class Building{
string name;
int size;
string address;
public:
Building(){
name="";
size=0;
address="";
}
Building(string n,int s,string a){
name=n;
size=s;
address=a;
}
void set_name(string n){
name=n;
}
void set_size(int s){
size=s;
}
void set_address(string a){
address=a;
}
string get_name(){
return name;
}
int get_size(){
return size;
}
string get_address(){
return address;
}
};
class student:public person{
float CGP;
public:
student(){
person();
CGP=0;
}
void set_CGP(float cgp){
CGP=cgp;
}
float get_CGP(){
return CGP;
}
void do_work(){
cout<<get_name()<<"did "<<rand()*10+1<<" hours of homework ";
}
};
class instructor:public person{
float rating;
public:
instructor(){
person();
rating=0;
}
void set_rating(float rate){
rating=rate;
}
float get_rating(){
return rating;
}
void do_work(){
cout<<get_name()<<" graded paper for "<<rand()*10+1<<" hours ";
}
};
class university{
string name;
Building *b;
student*s;
instructor*in;
public:
university(string na,int m,int st,int i){
name=na;
b=new Building[m];
s=new student[st];
in=new instructor[i];
}
void set_name(string n){
name=n;
}
void set_buildings(int count,string n,int size,string address){
b[count].set_address(address);
b[count].set_name(n);
b[count].set_size(size);
}
void set_student(int i,float cgp,string name,int age){
s[i].set_name(name);
s[i].set_age(age);
s[i].set_CGP(cgp);
}
void set_instructor(int index,float rating,string name,int age){
in[index].set_name(name);
in[index].set_age(age);
in[index].set_rating(rating);
}
string get_name(){
return name;
}
void get_building(int index){
cout<<b[index].get_name()<<" "<<b[index].get_size()<<" "<<b[index].get_address()<<" ";
}
void get_student(int index){
cout<<s[index].get_name()<<" "<<s[index].get_age()<<s[index].get_CGP()<<" ";
}
void get_instructor(int index){
cout<<in[index].get_name()<<" "<<in[index].get_age()<<in[index].get_rating()<<" ";
}
void to_work_student(int num,string name){
for(int i=0;i<num;i++){
if(s[i].get_name()==name)s[i].do_work();
}
}
void to_work_instructor(int num,string name){
for(int i=0;i<num;i++){
if(in[i].get_name()==name)in[i].do_work();
}
}
};
int main(){
string name,address;
int m,s_count,i_count,size,age,choice,st,in;
float cgp,rating;
cout<<"Enter name of university : ";
cin>>name;
cout<<"Enter number of students in university : ";
cin>>s_count;
cout<<"Enter number of instructors in university : ";
cin>>i_count;
cout<<"Enter number of buldings in university : ";
cin>>m;
university U(name,m,s_count,i_count);
cout<<"set buildings ";
for(int i=0;i<m;i++){
cout<<"Enter name : ";
cin>>name;
cout<<"Enter size(in sqft) : ";
cin>>size;
cout<<"Enter address : ";
getline(cin,address);
U.set_buildings(i,name,size,address);
}
cout<<"set students ";
for(int i=0;i<s_count;i++){
cout<<"Enter name : ";
cin>>name;
cout<<"Enter age : ";
cin>>age;
cout<<"Enter cgp : ";
cin>>cgp;
U.set_student(i,cgp,name,age);
}
cout<<"set instructors ";
for(int i=0;i<s_count;i++){
cout<<"Enter name : ";
cin>>name;
cout<<"Enter age : ";
cin>>age;
cout<<"Enter rating : ";
cin>>rating;
U.set_student(i,rating,name,age);
}
do{
cout<<"1:print information about all buildings 2:print information of everybody in university 3:choose a person to do work 4:quit ";
cout<<"enter choice : ";
cin>>choice;
switch(choice){
case 1:{
for(int i=0;i<m;i++){
U.get_building(i);
}
break;
}
case 2:{cout<<"student information ";
for(int i;i<s_count;i++ )
U.get_student(i);
cout<<"instructor information ";
for(int i;i<i_count;i++ )
U.get_instructor(i);
break;
}
case 3:{
cout<<"1:student 2:instructor ";
int l;
cin>>l;
cout<<"Enter name : ";
cin>>name;
if(l==1){
U.to_work_student(s_count,name);
}
else if(l==2){
U.to_work_instructor(i_count,name);
}
break;
}
}
}while(choice!=4);
return 0;
}