Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program that loops through all of the command line arguments that ar

ID: 3876558 • Letter: W

Question

Write a C++ program that loops through all of the command line arguments that are passed to the program, beginning with the argument after the program name. The first command line argument must be the string “small”, “medium” or “large”. We define small to mean size 5, medium to mean size 10, and large to mean size 20. If the first command line argument is missing, your program should print MISSING SIZE and stop. If the first command line argument is not the string “small”, “medium” or “large”, then your program should print the argument followed by a space and the message NOT A VALID SIZE, then should stop. For each command line argument after the first argument, your program should determine the length of the argument. If its length is greater than or equal to the size specified by the first command line argument, then the program should print the argument

Explanation / Answer

#include <iostream>

using namespace std;

int main()
{
while(1){
cout<<"Enter Input:"<<endl;
string str;
cin>>str;
int len=str.length();
switch(len){
case 0:
cout<<"Missing Size"<<endl;
exit(0);
case 5:
cout<<"The length of the string entered:Small"<<endl;
break;
case 10:
cout<<"The length of the string entered:Medium"<<endl;
break;
case 20:
cout<<"The length of the string entered:Large"<<endl;
break;
default:
cout<<"Not a valid size"<<endl;
exit(0);
}

}

return 0;
}

Hi please find the program above.

a string is an inbuilt data type of c++. So, you can use directly create a variable of type string to store the user input.

and length() is also an inbuilt function of string library. In this program, a switch case is used. we can determine the output of the switch for each case.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote