Draft: C ++ Leanguage Test generator Issue: Make a program that allows to create
ID: 3904619 • Letter: D
Question
Draft: C++ Leanguage
Test generator
Issue:
Make a program that allows to create exams of free questions. An example of an examination of free questions is:
First name:
ID:
Date:
Hour:
Questions:
1) Make a class whose objects represent, each, a date.
2) Make a class whose objects represent, each, one hour.
3) Make a class whose objects represent each one, a whole number. The class has to work as if it were the int type.
NOTE:
For this solution the use of the following classes is required:
myDate,
myTime,
menu,
myString,
list of chains,
header,
For all classes all their constructors, destructor and services of the classes are required. The int main function is also required to test all classes
Explanation / Answer
This c++14 program will run on GNU GC7.1.1 compiler. You can add, delete and view all the tests you have generated. Along with the contructors the getter and setters have been written for each classes to acept and return the values from each class. Hope you get the code it's very simple and easy to understand.
#include <iostream>
#include <string>
using namespace std;
#define max 5
//myDate class
class myDate {
public:
void setDate( string t );
string getDate( void );
myDate(); // This is the constructor
private:
string Date;
};
// Member functions definitions including constructor
myDate::myDate(void) {
Date="00/00/0000";
}
void myDate::setDate( string d) {
Date = d;
}
string myDate::getDate( void ) {
return Date;
}
//myTime class
class myTime {
public:
void setTime( string t );
string getTime( void );
myTime(); // This is the constructor
private:
string Time;
};
// Member functions definitions including constructor
myTime::myTime(void) {
Time="00:00Hrs";
}
void myTime::setTime( string t) {
Time = t;
}
string myTime::getTime( void ) {
return Time;
}
//menu class
class menu{
public:
void display(void);
void setChoice();
int getChoice(void);
menu();
private:
int c;
};
menu::menu(void) {
c=-1;
}
void menu::display(void){
cout<<" ********** MENU ********** 1. create a new exam 2. Delete an Exam 3. Show all exams 4. Exit Enter Your Choice(1-4): ";
}
void menu::setChoice(void) {
cin>>c;
}
int menu::getChoice( void ) {
return c;
}
//class header
class header{
public:
void setHeader(int id,string n);
int getid(void);string getname(void);
header();
private:
int ID;
string name;
};
void header::setHeader(int id,string n){
ID=id;
name=n;
}
int header::getid(void){
return ID;
}
string header::getname(void){
return name;
}
header::header(){
ID=-1;
name="XXXXXXX";
}
//mySTring lass to store list of questions
class myString{
public:
void addQuestions();
void showQuestions();
myString();
private:
string questions[10];
int i;
};
void myString::addQuestions(){
for(i=0;i<10;i++){
questions[i]="This is my question number "+(i+1);
}
}
void myString::showQuestions(){
for(i=0;i<10;i++){
cout<<" "<<questions[i];
}
}
myString::myString(){
for(i=0;i<10;i++){
questions[i]=""; //store null
}
}
// Main function for the program
int main() {
int i=0;
string t,name="My Exam",date="15/06/2018",t="1:30Hrs";
myTime Time[max];
myDate Date[max];
header H[max];
myString Q[max];
menu Menu;
// set line length
Menu.display();
Menu.setChoice();
int ch = Menu.getChoice();
while(ch>0 && ch <5)
{
swith(ch){
case 1:
if(i<10)
{
//cin>>i>>name; to get name and id for exam
H[i].setHeader(i,name);
cout<<" ID: "<<H[i].getid()<<" Name: "<<H[i].getname();
//cin>>date; to get date for exam
Date[i].setDate(date);
cout << " The Date is: " << Date[i].getDate();
//cin>>t; to get duration of exam
Time[i].setTime(t);
cout << " The Time is: " << Time[i].getTime();
Q[i].addQuestions();
Q[i].showQuestions();
cout<<" Exam added";
i++;
}else
cout<<" space full! No more exam can be added";
break;
case 2:
cout<<" Enter exam ID to delete";
int eid;
cin>>eid;
H[i].setHeader(-1,"XXXXXXX");
cout<<" ID: "<<H[i].getid()<<" Name: "<<H[i].getname();
Date[i].setDate("00/00/0000");
cout << " The Date is: " << Date[i].getDate();
Time[i].setTime("00:00Hrs");
cout << " The Time is: " << Time[i].getTime();
Q[i].addQuestions();
Q[i].showQuestions();
cout<<" Exam Deleted!";
break;
case 3:
for (int k =0;k<i;k++)
{
cout<<" ID: "<<H[k].getid()<<" Name: "<<H[k].getname();
cout << " The Date is: " << Date[k].getDate();
cout << " The Time is: " << Time[k].getTime();
Q[i].showQuestions();
cout<<" -------------------------------------------------------------------------------------------------------- ";
}
break;
case 4:
exit(0);
break;
default:
cout<<" try again!! Invalid Input.";
Menu.display();
Menu.setChoice();
ch = Menu.getChoice();
break;
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.