CIS022_S2017_Assignment10b your name Select a location where you can find it lat
ID: 3828774 • Letter: C
Question
CIS022_S2017_Assignment10b your name
Select a location where you can find it later
Choose the default application settings
Replace the entire contents of your CIS022_S2017_Assignment10b your name.cpp with the contents of the given file.
#include <iostream>
#include <string>
using namespace std;
in MessageClass.h just above the class definition.
Yes, there are easier ways to perform these tasks, but I want you to do it this way.
This is the code inside of the cpp file:
#include "stdafx.h"#include <iostream>#include <string>
#include "MessageClass.h"using namespace std;int _tmain(int argc, _TCHAR* argv[])
{
MessageClass msg;msg.MessageBox("Welcome to CIS 022 from Mark Berrett", 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;
}
1. Create a new Visual C++ Win32 Console application and name it:CIS022_S2017_Assignment10b your name
Select a location where you can find it later
Choose the default application settings
CIS022_S2017_Assignment10b.cpp
Replace the entire contents of your CIS022_S2017_Assignment10b your name.cpp with the contents of the given file.
3. Complete the project.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 <iostream>
#include <string>
using namespace std;
in MessageClass.h just above the class definition.
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:
Note that output to the console is performed from within the MessageBox() method.
MessageBox() should be flexible enough to allow me to make changes to the strings in the call in the main() function and it will produce the similar, working results. Assume that the second string (the box header) will always be sufficiently smaller than the first string (box message).
Yes, there are easier ways to perform these tasks, but I want you to do it this way.
This is the code inside of the cpp file:
#include "stdafx.h"#include <iostream>#include <string>
#include "MessageClass.h"using namespace std;int _tmain(int argc, _TCHAR* argv[])
{
MessageClass msg;msg.MessageBox("Welcome to CIS 022 from Mark Berrett", 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
//MessageClass.h
#include <iostream>
#include <string>
using namespace std;
class MessageClass
{
public:
const int Bonk = 0;
const int Question = 1;
const int Information = 2;
const int Wink = 3;
char arr_emphasis[4];
MessageClass()
{
arr_emphasis[0] = '!';
arr_emphasis[1] = '?';
arr_emphasis[2] = 'i';
arr_emphasis[3] = ';';
}
void MessageBox(string str1, int index, string str2)
{
cout << str1 << arr_emphasis[index] << str2;
}
};
//MessageClass.cpp
// MessageClass.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "MessageClass.h"
int _tmain(int argc, _TCHAR* argv[])
{
MessageClass msg;
msg.MessageBox("Welcome to CIS 022 from Mark Berrett", 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;
}