Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

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

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige

Hier ansehen

1 von 2 Anzeige

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

Herunterladen, um offline zu lesen

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

Weitere von lez31palka (20)

Aktuellste (20)

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; }

×