In: Computer Science
Create a class called College that has:
Write two unsorted lists that manage the data for colleges and their ranking:
Each college will have a unique ID number that will be used for search.
For the lab you don't need to read the commands from a file. Your commands will be hard-coded as function calls within your main() function.
The following actions will be performed twice: once with the array and once with the linked list. Make sure your code is clearly marked with comments, so the grader can easily see which actions were performed with each structure.
C++language
IDE used: Dev C++
Parts done in unsorted array
Add 5 colleges
Print your list of colleges
Search for a college by college ID (it will print all the
information about the college)
Print your list of colleges
Add 4 more colleges
Change the info in 1 college
Change the info in 1 college
Print all colleges
Add one more college
Print all colleges
Program
#include <iostream>
#include <string>
using namespace std;
class college{
private :
string name;
string location;
string type;
int college_id;
int rank;
public:
//default constructor
college()
{
name = "";
location =
"";
type ="";
college_id=0;
rank =0;
}
//parametarised constructor
college(string Name, string
Location, string Type, int id, int Rank)
{
name = Name;
location =
Location;
type =
Type;
college_id=id;
rank =
Rank;
}
//Destructor
/*~college()
{
cout<<"College Removed";
}*/
//all the setters
void setname(string Name)
{
name =
Name;
}
void setlocation(string
Location)
{
location =
Location;
}
void settype(string Type)
{
type =
Type;
}
void setid(int id)
{
college_id=id;
}
void setrank(int Rank)
{
rank =
Rank;
}
//all the getter
string getname()
{
return
name;
}
string getlocation()
{
return
location;
}
string gettype()
{
return
type;
}
int getid()
{
return
college_id;
}
int getrank()
{
return
rank;
}
//function to print data
void print_me()
{
cout<<"\nCollege Id:
"<<getid()<<", Name: "<<getname()<<",
Location: "<<getlocation()
<<", Type: "<<gettype()<<",
Rank: "<<getrank();
}
//function to search college
void search(int id)
{
if(college_id==id)
{
cout<<"\nCollege Id:
"<<getid()<<", Name: "<<getname()<<",
Location: "<<getlocation()
<<", Type: "<<gettype()<<",
Rank: "<<getrank();
}
else
{
cout<<"Invalid colleged Id";
}
}
//function to add new college
void add_new(string Name, string
Location, string Type, int id, int Rank)
{
name =
Name;
location =
Location;
type =
Type;
college_id=id;
rank =
Rank;
cout<<"\nCollege added succesdully!";
}
//fucntion to update data
void update_data(int id)
{
char Name[30];
char Location[30];
char Type[30];
int Rank;
if(college_id==id)
{
cout<<"\nName: ";
cin>>Name;
setname(Name);
cout<<"\nLocation";
cin>>Location;
setlocation(Location);
cout<<"\nType";
cin>>Type;
settype(Type);
cout<<"\nRank: ";
cin>>Rank;
setrank(Rank);
cout<<"Update successful";
}
else
{
cout<<"Invalid College Id";
}
}
/*void removecol()
{
~college();
}*/
};
int main()
{
int i;
college col[50]; //array of college object
//add 5 college
col[0].add_new("SRT
college","England","Business",1230,9);
col[1].add_new("VDS
college","USA","Medical",1231,6);
col[2].add_new("MTI
college","USA","Engineering",1232,7);
col[3].add_new("STF
college","England","Law",1233,5);
col[4].add_new("COL
college","USA","ARTS",1234,10);
//print collges
for(i =0;i<5;i++)
{
col[i].print_me();
cout<<endl;
}
//search college using id
cout<<"\nSearch Result";
col[1].search(1231);
//print all college
cout<<"\nCollege data";
for(i =0;i<5;i++)
{
col[i].print_me();
cout<<endl;
}
//add 4 more colleges
col[5].add_new("PTR
college","England","Business",1235,1);
col[6].add_new("MANU
college","USA","Medical",1236,14);
col[7].add_new("PSG
college","USA","Engineering",1237,18);
col[8].add_new("POM
college","England","Law",1238,3);
//update 2 colleges
cout<<"\nUpdation";
cout<<"\nEnter the new data";
col[1].update_data(1231);
cout<<"\nEnter the new data";
col[5].update_data(1235);
//print all colleges
cout<<"\nCollege data";
for(i =0;i<9;i++)
{
col[i].print_me();
cout<<endl;
}
//add one more college
col[9].add_new("BRC
college","USA","MBBS",1238,1);
//show all college
cout<<"\nCollege data";
for(i =0;i<10;i++)
{
col[i].print_me();
cout<<endl;
}
}