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

Define and implement class Course. This class should contain the following fields: course name, course description,...
Define and implement class Course. This class should contain the following fields: course name, course description, department, time the course starts, weekday the course is held on (for simplicity, let us assume the course only meets once a week). This class should contain getters and setters for all its attributes. This class also needs at least one constructor. Save this class and its definition into a file named Course.java. Define and implement class Student. This class should contain the following...
in java, write code that defines a class named Cat The class should have breed, name...
in java, write code that defines a class named Cat The class should have breed, name and weight as attributes. include setters and getters for the methods for each attribute. include a toString method that prints out the object created from the class, and a welcome message. And use a constructor that takes in all the attributes to create an object.
Description Write a program that prints out your name, the course ID of this class, what...
Description Write a program that prints out your name, the course ID of this class, what programming/computer courses you've taken. Ask the user for two numbers. Show the sum of the two numbers, the difference, the product and the quotient. For the difference subtract the second number from the first, for the quotient, use the first number as the numerator(dividend) and the second as the denominator(divisor). Sample Output: My name is Jianan Liu, I'm in course CS36. I've taken: C...
Relation : course(course id, title, dept name, credits) Explain how to create different indices: primary index,...
Relation : course(course id, title, dept name, credits) Explain how to create different indices: primary index, secondary index, dense index, sparse index, respectively. Using above relation, you can either describe based on the definition of the indices or answer with the instance of the relation using some fake data/tuples.
Declare and initialize an array to store the course name or code.
Declare and initialize an array to store the course name or code.
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....
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 *
1. Write the SQL code required to list the employee number, first and last name, middle...
1. Write the SQL code required to list the employee number, first and last name, middle initial, and the hire date. Sort your selection by the hire date, to display the newly hired employees first. 2. Modify the previous query and list the employee first, last name and middle initial as one column with the title EMP_NAME. Make sure the names are listed in the following format: First name, space, initial, space, last name (e.g. John T Doe). Hint: use...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT