Program Name: Character Strings (Please use only C++ programming method- Microso
ID: 3758681 • Letter: P
Question
Program Name: Character Strings
(Please use only C++ programming method- Microsoft Visual Studio 2010 C++ Express or later).
Procedure:
1. Write a program that takes several character strings and assembles them into one or more phrases.
2. Create the following character strings:
- Hello
- Classmates
- ENGR 2304
- Course
- Is an
- Super
- Interesting
- Everybody
- C++ programming
- Introductory
1. Name the strings as numbered above, e.g. string str1=”Hello”
2. Create other strings as necessary to accomplish the phrase.
3. Create the following output string;
“Hello classmates, ENGR 2304 is an introductory C++ programming course. Everybody seems to think it is super interesting. “
Words must be separated by punctuations, such as spaces, commas, etc.
Write the output string to an output data file named pa12output.dat.
Explanation / Answer
#include<iostream>
#include<string.h>
#include<fstream>
using namespace std;
int main(){
ofstream file;
file.open("pa12output.dat");
string str1 = "Hello";
string str2 = "classmates";
string str3 = "ENGR 2304";
string str4 = "is";
string str5 = "an";
string str6 = "introductory";
string str7 = "C++";
string str8 = "programming";
string str9 = "course";
string str10 = "Everybody";
string str11 = "seems";
string str12 = "to";
string str13 = "think";
string str14 = "it";
string str15 = "super";
string str16 = "interesting";
string str = str1+" "+str2+", "+str3+" "+str4+" "+str5+" "+str6+" "+str7+" "+str8+" "+str9+". "+str10+" "+str11+" "+str12+" "+str13+" "+str14+" "+str15+" "+str16+".";
file<<str;
file.close();
cout<<str;
cout<<" ";
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.