Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Certificate Printing
/* ** Certificate printing** Certificates are being printed with the names of two people in a team. To make the certificate look balanced, the person with the shorter name should be shown first. Write a program that reads in two names, and prints the shorter name first. If they are the same length, then they should be printed in the order they were typed in. The length is based on the number of characters in the name. */ //g++ 5.4.0 #include <iostream> #include <string> using namespace std; int main() { // string input="test"; // std::cout <<input; //create string variable and assign elements string input1="Adam Apple"; string input2="Betty Banana"; string input3="Anthony Robins"; string input4="Tim Bell"; //create variable for full number of elements in string concatenate length() function //length functin returns an unsigned int data type and counts the length of array. int numChars1= input1.length(); int numChars2= input2.length(); int numChars3= input3.length(); int numChars4= input4.length(); /*count number of elements and decress space if there is one create index and make same data type as length function loop through index value and compare element and increas index each time if the contents of each element is equal to a space then decrement each time a space appear so that the numChars value is name length only and not spaces */ for (unsigned int i = 0; i < input1.length(); i++) { if (input1.at(i) == ' ') { numChars1--; } } for (unsigned int i = 0; i < input2.length(); i++) { if (input2.at(i) == ' ') { numChars2--; } } for (unsigned int i = 0; i < input3.length(); i++) { if (input3.at(i) == ' ') { numChars3--; } } for (unsigned int i = 0; i < input4.length(); i++) { if (input4.at(i) == ' ') { numChars4--; } } // std::cout <<input1<<" "<<" "<<numChars1<<", "; // std::cout <<input2<<" "<<" "<<numChars2<<'\n'; /* Compare length of names and print certificates */ if (((numChars1) < (numChars2))||((numChars1) == (numChars2))) { std::cout<<"First Certificate: "<<input1<<", "<<input2<<'\n'; } else if((numChars1) > (numChars2)) { std::cout<<"First Certificate: "<<input2<<", "<<input1<<'\n'; } // std::cout <<input3<<" "<<" "<<numChars3<<", "; // std::cout <<input4<<" "<<" "<<numChars4<<'\n'; if (((numChars3) < (numChars4))||((numChars3) == (numChars4))) { std::cout<<"Second Certificate: "<<input3<<", "<<input4<<'\n'; } else if((numChars3) > (numChars4)) { std::cout<<"Second Certificate: "<<input4<<", "<<input3<<'\n'; } return 0; }
run
|
edit
|
history
|
help
0
ArrAdSubMul
Kth smallest element
threadpool03
mytemp
Sekhejane link
RCP 27
NonparaH
StrStrPbrk
template
BubDoubArray