In: Computer Science
Design and implement a C++ class called Module that handles information regarding your assignments for a specific module. Think of all the things you would want to do with such a class and write corresponding member functions for your Module class. Your class declaration should be well-documented so that users will know how to use it.
Write a main program that does the following:
Declare an array of all your modules. The elements of the array must be of type Module.
Initialize the array with the modules you are registered for e.g. "COS1512", "INF1511", "COS1506". Initialize each module with the assignment marks you have obtained for the module (or would like to obtain for the module).
Determine your semester mark for each module: the first assignment contributes 30% and the second assignment 70%. Display the semester marks.
Adjust the marks for Assignment 2 for COS1512 with +5%.
Determine your semester mark for COS1512 again to see what effect the update had.
Display an updated list of your semester marks for all the modules you are registered for.
Answer :
#include
using namespace std;
class module
{
string m_name; //name of the module
float per1; //first assignment contributes how much
percent
float per2; //second assignment contributes how much
percent
float total; //total semester marks
float m1; //first assignment marks out of
100
float m2; //second assignment marks out of
100
public:
void set_module(string name) //set the module
name and contribution of both assignments
{
m_name=name;
per1=0.3;
per2=0.7;
}
void marks(float marks1,float marks2) //marks
calculation
{
total=per1*marks1+per2*marks2;
}
void modify() //modify contributions assignment2
contribution becomes +5%=70+5=75% and assignment1
25%
{
per1=0.25;
per2=0.75;
}
void print() //print module name and marks
{
cout<<"Module name : "<
string module_name() //returns the module
name
{
return m_name;
}
float marks1() //returns marks in assignment1 inputted by
user
{
return m1;
}
float marks2() //returns marks in assignment2 inputted by
user
{
return m2;
}
};
int main()
{
module m[3]; //array of module type objects
//set the module name and contributions of
assignments
m[0].set_module("COS1512");
m[1].set_module("INF1511");
m[2].set_module("COS1506");
float mark1,mark2;
//enter marks for each module by user //print information of modules //if module name is COS1512 then modify the assignment2
contribution to +5% that is it becomes 75% and assignment1 becomes
25% } //print information after updation for(int i=0;i<3;i++) } Output :
for(int i=0;i<3;i++)
{
cout<<"Enter assignment marks for module
"<
cin>>mark1;
cout<<"Enter marks obtained in assignment2(out of 100) :
";
cin>>mark2;
m[i].marks(mark1,mark2);
}
cout<
for(int i=0;i<3;i++)
{
m[i].print();
}
cout<
for(int i=0;i<3;i++)
{
string s=m[i].module_name();
if(s=="COS1512")
{
m[i].modify();
m[i].marks(m[i].marks1(),m[i].marks2());
}
cout<<"After updation : "<
{
m[i].print();
}