Answer to Question #210349 in C++ for Ree

Question #210349

Consider the following structure used to keep record of a module: struct Module { string moduleName; string moduleCode; string lecturer; int nrStudents; } Turn the Module struct into a class. The class should have member variables for all the values in the corresponding struct. Make all the member variables private. Include public member functions for each of the following: a default constructor that sets the string member variables to blank strings, and the int member variable to 0 overloaded constructor that sets the member variables to specified values;  member functions to set each of the member variables to a value given as an argument to the function member functions to retrieve the data from each of the member variables Test the class in a program that instantiates an object of class Module. The program should then input values for the object and use the mutators to assign values to the member variables. Use the accessors to obtain the values


1
Expert's answer
2021-06-25T05:21:54-0400


#include <iostream>


using namespace std;


class Module { 
    private:
        string moduleName; 
        string moduleCode; 
        string lecturer; 
        int nrStudents; 
    public:
        Module(){
            moduleName="";
            moduleCode="";
            lecturer="";
            nrStudents=0;
        }
        Module(string mn,string mc, string l, int ns){
            moduleName=mn;
            moduleCode=mc;
            lecturer=l;
            nrStudents=ns;
        }
        void setModuleName(string mname){
            moduleName=mname;
        }
        void setModuleCode(string mcode){
            moduleCode=mcode;
        }
        void setLecture(string lec){
            lecturer=lec;
        }
        void setNrStudents(int nr){
            nrStudents=nr;
        }
        string getModuleName(){
            return moduleName;
        }
        string getModuleCode(){
            return moduleCode;
        }
        string getLecture(){
            return lecturer;
        }
        int getNrStudents(){
            return nrStudents;
        }
};


int main()
{
    Module m;
    m.setModuleName("Computer Science");
    m.setModuleCode("BCS 123");
    m.setLecture("Dr. John");
    m.setNrStudents(45);
    cout<<"\nModule name: "<<m.getModuleName();
    cout<<"\nModule code: "<<m.getModuleCode();
    cout<<"\nLecturer: "<<m.getLecture();
    cout<<"\nNumber of Students: "<<m.getNrStudents();
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS