Question

In: Computer Science

Design and implement a C++ class called Module that handles information regarding your assignments for a specific module.


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.

Solutions

Expert Solution

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 : "< cout<<"Semester marks : "< cout<<"-----------------------------------"< }
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
for(int i=0;i<3;i++)
{
cout<<"Enter assignment marks for module "< cout<<"------------------------------------------------------------"< cout<<"Enter marks obtained in assignment1(out of 100) : ";
cin>>mark1;
cout<<"Enter marks obtained in assignment2(out of 100) : ";
cin>>mark2;
m[i].marks(mark1,mark2);
}
cout<

//print information of modules
for(int i=0;i<3;i++)
{
m[i].print();
}
cout<

//if module name is COS1512 then modify the assignment2 contribution to +5% that is it becomes 75% and assignment1 becomes 25%
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());
}

}

//print information after updation
cout<<"After updation : "<

for(int i=0;i<3;i++)
{
m[i].print();
}

}

Output :


Related Solutions

1) Design an implement a program that created and exception class called StringTooLongException, designed to be...
1) Design an implement a program that created and exception class called StringTooLongException, designed to be thrown when a string is discovered that has too many characters in it. Create a driver that reads in strings from the user until the user enters DONE. If a string that has more then 5 characters is entered, throw the exception. Allow the thrown exception to terminate the program 2) Create a class called TestScore that has a constructor that accepts an array...
JAVA - Design and implement a class called Flight that represents an airline flight. It should...
JAVA - Design and implement a class called Flight that represents an airline flight. It should contain instance data that represent the airline name, the flight number, and the flight’s origin and destination cities. Define the Flight constructor to accept and initialize all instance data. Include getter and setter methods for all instance data. Include a toString method that returns a one-line description of the flight. Create a driver class called FlightTest, whose main method instantiates and updates several Flight...
DO THIS IN C#,Design and implement class Rectangle to represent a rectangle object. The class defines...
DO THIS IN C#,Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: 1. Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. 2. A non-argument constructor method to create a default rectangle. 3. Another constructor method to create a rectangle with user-specified height and width. 4. Method getArea() that returns...
IN C++!!! Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class...
IN C++!!! Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 0 in the default constructor. A non-argument constructor method to create a default rectangle. Another constructor method to create a rectangle with user-specified height and width. Method getArea() that returns the area. Method...
In C++, implement a class called setOper that provides several simple set operations. The class only...
In C++, implement a class called setOper that provides several simple set operations. The class only needs to deal with sets that are closed intervals specified by two real numbers; for example, the pair (2.5, 4.5) represent the interval [2.5, 4.5]. The following operations should be supported: - Check if the value x belongs to the given interval. - Check if the value x belongs to the intersection of two intervals. - Check if the value x belongs to the...
Question : Design and implement two classes called InfixToPostfix and PostFixCalculator. The InfixToPrefix class converts an...
Question : Design and implement two classes called InfixToPostfix and PostFixCalculator. The InfixToPrefix class converts an infix expression to a postfix expression. The PostFixCalculator class evaluates a postfix expression. This means that the expressions will have already been converted into correct postfix form. Write a main method that prompts the user to enter an expression in the infix form, converts it into postfix, displays the postfix expression as well as it's evaluation. For simplicity, use only these operators, + ,...
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...
Problem 2 (C++): Design and implement a class complexType, that can be used to process complex...
Problem 2 (C++): Design and implement a class complexType, that can be used to process complex numbers. A number of the form a +ib, in which i2 = -1 and a and b are real numbers, is called a complex number. We call a the real part and b the imaginary part of a + ib. Complex numbers can also be represented as ordered pairs (a, b). The class you will design should have the following features. Constructor Your class...
For this assignment, implement and use the methods for a class called Seller that represents information about a salesperson.
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...
ROCK, PAPER, SCISSORS Using C++, you will implement a class called Tool. It should have an...
ROCK, PAPER, SCISSORS Using C++, you will implement a class called Tool. It should have an int field called strength and a char field called type. You may make them either private or protected. The Tool class should also contain the function void setStrength(int), which sets the strength for the Tool. Create 3 more classes called Rock, Paper, and Scissors, which inherit from Tool. Each of these classes will need a default constructor that sets the strength to 1 and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT