Question

In: Computer Science

Write a class Roster that is identified by the course name, course code, number of credits,...

Write a class Roster that is identified by the course name, course code, number of credits, instructor name, and contains a list of students stored in an array. For now you can use stack allocated array of MAX_CAPACITY=10 (define MAX_CAPACITY as a macro in the .h file). Later we will make this array dynamic to allow it to grow. Provide necessary constructors, accessor functions for each member, and mutator functions for each member. Provide a function to add a student to a Roster, delete student from a Roster, and search for a student. Provide a function to output all Students from a roster to console in a nice format.

For now you should not worry about the order of Students in your Roster. They do not need to be sorted.

Write a driver program to test your Roster class.

Use declare/define/use approach

Solutions

Expert Solution

#include<bits/stdc++.h>
#define MAX_CAPACITY 10
using namespace std;

class Roaster{
        private:
                string name;
                string code;
                int numOfCredits;
                string instructorName;
                string studentName[MAX_CAPACITY];
            int index;
        public:

                Roaster(string name,string code,int numOfCredits,string instructorName)
                {
                        this->name=name;
                        this->code=code;
                        this->numOfCredits=numOfCredits;
                        this->instructorName=instructorName;
                        this->index=-1;

                }

                void setName(string name)
                {
                        this->name=name;
                }
                void setCode(string code)
                {
                        this->code=code;
                }
                void setNumberOfCredit(int credit)
                {
                        this->numOfCredits=credit;
                }
                void setInstructorName(string name)
                {
                        this->instructorName=name;
                }

                string getName()
                {
                return this->name;
            }
                string getCode()
                {
                return this->code;
        }
                int getNumberOfCredits()
                {
                return this->numOfCredits;
        }
                string getInstructorName()
                {
                return this->instructorName;
        }


                void addStrudent(string name)
                {
                        this->studentName[++index]=name;
                }

                int searchStudent(string name)
                {
                        int i;  
                for (i = 0; i <=index; i++)  
                        if (studentName[i] == name)  
                        return i;  
  
                        return -1;  
                }

                void deleteStudent(string name)
                {
                        int pos = searchStudent(name);  
  
                if (pos == - 1)  
                {  
                        cout << "Student not found";  
                          
                }  
  
                // Deleting element  
                int i;  
                for (i = pos; i <=index-1; i++)  
                        studentName[i] = studentName[i + 1];  
  
                 index=index-1;  
                }

                void printStudent()
                {

                        for(int i=0;i<=index;i++)
                        {
                                cout<<studentName[i]<<endl;
                        }
                }



};

int main()
{
          Roaster roaster("CSE","CSE101",12,"Anirban");

          roaster.addStrudent("chandan");

          roaster.addStrudent("Alex");

          roaster.addStrudent("David");

          roaster.addStrudent("Malan");

          roaster.printStudent();

          cout<<"\n\n";

          roaster.deleteStudent("Malan");

          roaster.printStudent();


          cout<<roaster.searchStudent("David")<<endl;
}

Related Solutions

Declare and initialize an array to store the course name or code.
Declare and initialize an array to store the course name or code.
Code in Java Write a Student class which has two instance variables, ID and name. This...
Code in Java Write a Student class which has two instance variables, ID and name. This class should have a two-parameter constructor that will set the value of ID and name variables. Write setters and getters for both instance variables. The setter for ID should check if the length of ID lies between 6 to 8 and setter for name should check that the length of name should lie between 0 to 20. If the value could not be set,...
Write a Class called Module with the following attributes: module code, module name, list of lecturers...
Write a Class called Module with the following attributes: module code, module name, list of lecturers for the module (some modules may have more than one lecturer – we only want to store their names), number of lecture hours, and module description. Create a parameterised (with parameters for all of the class attributes) and a non-parameterised constructor, and have the accessor and mutator methods for each attribute including a toString method. Write a class Student with the following attributes: student...
#python #code #AP class #Tech write a function code script which will print out number pyramid...
#python #code #AP class #Tech write a function code script which will print out number pyramid in the form of * so the output will be made up of **** resting on top of each other to form a pyramid shape. Bottom layer should be made of 5 multiplication signs like ***** then next 4 multiplication signs and so on. Top part should have only one *
Write a class named ContactEntry that has fields for a person’s name, phone number and email...
Write a class named ContactEntry that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five ContactEntry objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to demonstrate that it works. I repeat, NO-ARG constructors....
write the code based on this pseudocode //Create Class any name (ex: aQ) //Declaring private integer...
write the code based on this pseudocode //Create Class any name (ex: aQ) //Declaring private integer array empty one ex: name arrQ[] //Declare private integers front, rear, size and len (example, but you call any other names) //Write constructors Called public and same name of the class (parameters integer n) Inside Declare where: size is equal to n len is equal to zero arrQ is equal to new integer[size] front is equal minus 1 rear is equal minus 1 //Declare...
Write a c++ code: 2.2.1 Vehicle Class The vehicle class is the parent class of a...
Write a c++ code: 2.2.1 Vehicle Class The vehicle class is the parent class of a derived class: locomotive. Their inheritance will be public inheritance so react that appropriately in their .h les. The description of the vehicle class is given in the simple UML diagram below: vehicle -map: char** -name: string -size:int -------------------------- +vehicle() +setName(s:string):void +getName():string +getMap():char** +getSize():int +setMap(s: string):void +getMapAt(x:int, y:int):char +vehicle() +operator--():void +determineRouteStatistics()=0:void The class variables are as follows: map: A 2D array of chars, it will...
Create a new worksheet and name it as “Roster”. Assume that you are the TA for...
Create a new worksheet and name it as “Roster”. Assume that you are the TA for Mgtop 470. You have the class roster in the worksheet “Roster” and the full names of students are in column A, starting in Cell A3, with last name last and case insensitive (such as Ben ALT). Write a sub that counts the number of names in the list with last name ALT and then displays this count in an MsgBox that is titled “Number...
Write a bash script that will allow you to: Read in your Your name Course name...
Write a bash script that will allow you to: Read in your Your name Course name and Instructor’s name Then prompt the user to enter two numbers and determine which number is greater. Ex: If 10 is entered for the first number and 3 for the second, you should output Your name Course name Instructor’s name 10 is greater than 3. If 33 is entered for the first number and 100 for the second, you shou output Your name Course...
The attached csv, Projects.csv, has the grades for three projects of a class roster. Additional class...
The attached csv, Projects.csv, has the grades for three projects of a class roster. Additional class data includes student first and last name and their age. Your first task is to load the csv into a Pandas data frame. Afterwards, you must take steps to ensure no blank data persists in the data frame. Following that, you are expected to: • Calculate the mean and standard deviation of the three projects and print them to standard output • Create a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT