Write an interactive C++ program that inputs a name from the user in the followi
ID: 3571277 • Letter: W
Question
Write an interactive C++ program that inputs a name from the user in the following format Last, first middle The program should then output the name in the following format First Middle Last The program will have to use string operations to remove the comma from the end of the last name. The input should have an appropriate prompt, and the output should be labeled clearly and formatted neatly. Write a C++ program that reads in 5 integer input values and compute the summation of the inputted numbers and display the output.Explanation / Answer
1)
#include <iostream>
#include <string>
using namespace std;
int main(){
string first, middle, last;
cout << "Enter the name in the below format last, first middle ";
cin >> last >> first >> middle;
cout << "first middle last ";
// erase the comma
last.erase(last.begin() + last.size() - 1);
cout << first << " "<< middle <<" "<< last << endl;
return 0;
}
Enter the name in the below format
last, first middle
michael,
son
john
first middle last
son john michael
2)
#include <iostream>
using namespace std;
int main(){
int ans = 0;
cout << "Enter the five number ";
for(int i = 0;i < 5;++i){
int inp;
cin >> inp;
ans += inp;
}
cout <<"Summation of 5 numbers is "<< ans << endl;
}
Enter the five number
2 45 1 2 3
Summation of 5 numbers is 53
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.