Diese Präsentation wurde erfolgreich gemeldet.

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
×

1 von 2 Anzeige

# Write a C++ program that use your first and last name as a string- exa.docx

Write a C++ program that use your first and last name as a string.
example name ABCXYZ
Write a program that generates the following output, using 4 separate loops
\$                              OR                              N
C\$X                                                            HNS
BC\$XY                                                      OHNSO
ABC\$XYZ                                                 JOHNSON
Solution
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
int i;
for(i=1;i<=3;i++)
{
string s1=\"ABC\";
s1.erase (i,s1.size());
s1.append(\"\$\");
string s2=\"XYZ\";
s2.erase (i,s2.size());
s1.append(s2);
std::cout << s1 << \'\ \';
}
return 0;
}
.

Write a C++ program that use your first and last name as a string.
example name ABCXYZ
Write a program that generates the following output, using 4 separate loops
\$                              OR                              N
C\$X                                                            HNS
BC\$XY                                                      OHNSO
ABC\$XYZ                                                 JOHNSON
Solution
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
int i;
for(i=1;i<=3;i++)
{
string s1=\"ABC\";
s1.erase (i,s1.size());
s1.append(\"\$\");
string s2=\"XYZ\";
s2.erase (i,s2.size());
s1.append(s2);
std::cout << s1 << \'\ \';
}
return 0;
}
.

Anzeige
Anzeige

## Weitere Verwandte Inhalte

Anzeige

### Write a C++ program that use your first and last name as a string- exa.docx

1. 1. Write a C++ program that use your first and last name as a string. example name ABCXYZ Write a program that generates the following output, using 4 separate loops \$ OR N C\$X HNS BC\$XY OHNSO ABC\$XYZ JOHNSON Solution #include <iostream> #include <string> using namespace std; int main(int argc, char* argv[]) { int i; for(i=1;i<=3;i++) { string s1="ABC"; s1.erase (i,s1.size()); s1.append("\$"); string s2="XYZ"; s2.erase (i,s2.size()); s1.append(s2); std::cout << s1 << ' '; }
2. 2. return 0; }