Programming Language C++: Make NO changes to the provided code. Create a class n
ID: 3818722 • Letter: P
Question
Programming Language C++:
Make NO changes to the provided code.
Create a class named MessageClass with the following attributes:
A. A public method called MessageBox that accepts three parameters: String, integer, and string.
Hint: Don't forget to include the three lines:
#include
#include
using namespace std;
in MessageClass.h just above the class definition.
B. Include 4 constants of type int in the header file that define Bonk, Question, Information and Wink so that main() can reference them in the call to MessageBox().
C. Create, initialize and use an array that holds the four emphasis characters, !, ?, i, and ; that align with the constants in Step B and the integer passed into the MessageBox() function.
D. In the code section of the MessageBox() method, create code that reproduces the following results:
------------------------------------------------------------------------------------------------
Main Function Contains This Code
#include "stdafx.h"
#include
#include
#include "MessageClass.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
MessageClass msg;
msg.MessageBox("Welcome to Class", msg.Bonk, "Hello");
cout << endl;
msg.MessageBox("Why did the chicken cross the road", msg.Question, "Why");
cout << endl;
msg.MessageBox("To get to the other side", msg.Information, "Because");
cout << endl;
msg.MessageBox("That is all", msg.Wink, "Thank you");
cout << endl;
system("Pause");
return 0;
}
Explanation / Answer
Hi Student,
you should keep this header file and main fucntion file in same folder. The code for header file is :
#ifndef MESSAGECLASS_H
#define MESSAGECLASS_H
#include
#include
#include <iostream>
# include <string>
using namespace std;
class MessageClass
{
const int Bonk=0, Question=1, Information=2, Wink=3;
char array[4]={'!','?','i',';'};
public:
void MessageBox(string message, int num, string title){
for (int i=0; i<strlen(message); i++){
cout << array[num];
if(i==2)
cout<<" " + title + " ";
i=i+strlen(title)+2;
}
cout<<endl;
cout <<array[num];
for (int j=0; j <=strlen(message); j++){
cout << array[num];
if(j=1)
cout<<" " + message + " ";
j=j+strlen(message);
}
cout<<endl;
cout <<array[num];
for (int k=0; k < strlen(message); k++)
cout << array[num];
}
}MessageClass;
#endif
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.