Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

This is a C++Programming question Make a Module for a Mark to encapsulate a mark between 0 and 100 . Mark Grade Scale 4 mark

This is a C++Programming question

Make a Module for a Mark to encapsulate a mark between 0 and 100.

Mark Grade Scale 4 mark

0 =< Mark < 50 F 0.0

50 <= Mark < 60 D 1.0

60 <= Mark < 70 C 2.0

70 <= Mark < 80 B 3.0

80 <= Mark <= 100 A 4.0

The class nam

Important: No values are allowed to be kept in mark out of the range of 0 to 100. In any circumstance and during any function if the value goes below 0 or above 100, the mark is set to an invalid empty state. This condition will not be repeated in during the workshop and applies to all the functions and operators of class Marke must be Mark.

Construction

Mark can be created using on integer value (one argument constructor)that sets the value of the mark. If this value is not provided (no argument constructor), the value of the mark will be zero.

Mark m, n(25), k(200), p(-10);

// value of m is 0

// value of n is 25

// k is invalid

// p is invalid

Operator and conversion overloads

Mark can be casted to the an integer (int type). The result would be the value of the mark or zero if the mark is in an invalid state.

Mark m, n(25), k(200), p(-10);

cout << int(m) << endl;

cout << int(n) << endl;

cout << int(k) << endl;

cout << int(p) << endl;

Ouptut:

0

25

0

0

An integer can be added to the value of the mark using += operator; if the mark is invalid, the action is omitted. Reference of the mark is returned after the operation.

Mark m, n(25), k(200);

cout << int(m += 20) << endl;

cout << int(n += 20) << endl;

cout << int(k += 20) << endl;

cout << int(n += 60) << endl;

Output:

20

45

0

0

Mark can be set to an integer using the assignment operator. If the mark is in an invalid state, the invalid value can be corrected by the assignment.Reference of the mark is returned after the operation.

Mark m, n(25), k(200);

cout << int(m = 80) << endl;

cout << int(n = 120) << endl;

cout << int(k = 70) << endl;

Output:

80

0

70

Mark can be casted to a double, the result would be the GPA equivalent of the integer value. See the table of mark values above. Casting an invalid mark will result a zero value.

Mark m(50), n(80), k(120);

cout << double(m) << endl;

cout << double(n) << endl;

cout << double(k) << endl;

Output:

1

4

0

Mark can be casted to a character (char type), the result would be the grade letter value of the mark. See the table of mark values above. Casting an invalid mark will result a 'X' value.

Mark m(50), n(80), k(120);

cout << char(m) << endl;

cout << char(n) << endl;

cout << char(k) << endl;

Output:

D

A

X

Mark can be added to an integer, returning the integer after the operation. Invalid marks will not add any value to the integer.

Mark n(80), k(120);

cout << (val += n) << endl;

cout << (val += k) << endl;

Output:

140

140

##Tester program:

#include

#include "Mark.h"

using namespace std;

using namespace sdds;

int main() {

Mark m, n(25), k(200), p(-10);

cout << "int ............" << endl;

cout << int(m) << endl;

cout << int(n) << endl;

cout << int(k) << endl;

cout << int(p) << endl;

cout << "+= ............." << endl;

cout << int(m += 20) << endl;

cout << int(n += 20) << endl;

cout << int(k += 20) << endl;

cout << int(n += 60) << endl;

cout << "= .............." << endl;

cout << int(m = 80) << endl;

cout << int(n = 120) << endl;

cout << int(k = 70) << endl;

cout << "double ........." << endl;

m = 50; n = 80; k = 120;

cout << double(m) << endl;

cout << double(n) << endl;

cout << double(k) << endl;

cout << "char ..........." << endl;

cout << char(m) << endl;

cout << char(n) << endl;

cout << char(k) << endl;

cout << "int += Mark ..." << endl;

int val = 60;

cout << (val += n) << endl;

cout << (val += k) << endl;

return 0;

}

Here is the execution sample for the tester program

int ............

0

25

0

0

+= .............

20

45

0

0

= ..............

80

0

70

double .........

1

4

0

char ...........

D

A

X

int += Mark ...

140

140

Modify the tester program to test all the different circumstances/cases of the application if desired and not that the a new tester may have many more samples than the tester program here

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

Students explore these related Databases questions