Question

In: Computer Science

Create a class called College that has: At least 2 constructors (one should be the default...

Create a class called College that has:

  • At least 2 constructors (one should be the default constructor)
  • All members private
  • The relevant setters and getters
  • A print_me() function
  • A college_ID member (unique)

Write two unsorted lists that manage the data for colleges and their ranking:

  • An unsorted list using an array
  • An unsorted list using a linked list

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.

  • Add 5 colleges
  • Print your list of colleges
  • Remove 2 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

C++language

Solutions

Expert Solution

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;
   }
  
}


Related Solutions

Define the exception class called TornadoException. The class should have two constructors including one default constructor....
Define the exception class called TornadoException. The class should have two constructors including one default constructor. If the exception is thrown with the default constructor, the method getMessage should return "Tornado: Take cover immediately!" The other constructor has a single parameter, m, of int type. If the exception is thrown with this constructor, the getMessage should return "Tornado: m miles away; and approaching!" Write a Java program to test the class TornadoException.
Code a simple Editor class with 2 constructors (one default, one with a string for a...
Code a simple Editor class with 2 constructors (one default, one with a string for a file name) The Editor class in private has an instance of a LinkedList (of strings) and the position of the user (use our Point class) create a short file - at least 5 lines - could be a program main: string fileName("input.txt"); Editor miniVi (fileName); miniVi.displayLines(); C++ explain in detail plz Thank you
C++: 1.When and in what order are constructors and destructors called? 2. Create a class without...
C++: 1.When and in what order are constructors and destructors called? 2. Create a class without any constructors, and show that you can create objects with the default constructor. Now create a non-default constructor (one with an argument, aka parameterized constructor) for the class, and try compiling again. Explain what happened.
This class has two constructors. The default constructor (the one that takes no arguments) should initialize the first and last names to "None", the seller ID to "ZZZ999", and the sales total to 0.
For this assignment, implement and use the methods for a class called Seller that represents information about a salesperson.The Seller classUse the following class definition:class Seller { public:   Seller();   Seller( const char [], const char[], const char [], double );        void print();   void setFirstName( const char [] );   void setLastName( const char [] );   void setID( const char [] );   void setSalesTotal( double );   double getSalesTotal(); private:   char firstName[20];   char lastName[30];   char ID[7];   double salesTotal; };Data MembersThe data members for the class are:firstName holds the Seller's first namelastName holds the Seller's last nameID holds the Seller's id numbersalesTotal holds the Seller's sales totalConstructorsThis class has two constructors. The default constructor (the one that takes...
Java programming! Implement a static stack class of char. Your class should include two constructors. One...
Java programming! Implement a static stack class of char. Your class should include two constructors. One (no parameters) sets the size of the stack to 10. The other constructor accepts a single parameter specifying the desired size of the stack a push and pop operator an isEmpty and isFull method . Both return Booleans indicating the status of the stack Change this cods according to instructions please: public class Stack { int stackPtr; int data[]; public Stack() //constructor { stackPtr=0;...
Create 2 derived classes from Clothing class: Pants class Write only necessary constructors Override the wash()...
Create 2 derived classes from Clothing class: Pants class Write only necessary constructors Override the wash() method to indicate that pants are dry clean only. Include additional method hang() Add to your driver/tester file to make and print new pants objects and test it. Shirt class Include additional property of type string called sleeves. Write necessary constructors For sleeves only allow it to be set to {"short", "long", "none"} For size, only allow {"S","M","L"} Override the wash() method to indicate...
Create a file called grocery.ts. It should have a definition of a class with the obvious...
Create a file called grocery.ts. It should have a definition of a class with the obvious name Grocery. The class should have some basic attributes such as name, quantity, etc. Feel free to add any other attributes you think will be necessary. Add few grocery items to an array of groceries, such as milk, bread, and eggs, along with some quantities (i.e. 3, 6, 11). Display these grocery items as HTML output. The output of this assignment will be grocery.ts...
Inheritance Constructors Accessibility Accessibility Rules private         accessible within the same class. unspecified (friendly) (default)         additionally...
Inheritance Constructors Accessibility Accessibility Rules private         accessible within the same class. unspecified (friendly) (default)         additionally accessible to classes within the same package (folder). protected         additionally accessible to child classes. public         accessible to all classes. Description This assignment has two parts. Do the part I first and test it using the data in test run 1. Then do the second part and test it using data in test run 2 and test run 3. Submit the output from test run...
Q3) Design a class for saving data of employee, the class should have multiple constructors (constructor...
Q3) Design a class for saving data of employee, the class should have multiple constructors (constructor overloading) for initializing objects with different parameters. The employee class should have different functions for saving and updating bio-data, educational background, and current status like experience, Salary, position & travel history. The employee class should have a function which asks user what do he likes to see about employee (.i.e., Bio-data, current status....) and only show the respective data. Create two objects of interns...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT