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

GONZO CPP Write a program gonzo.cpp that takes 2 command line input arguments: a

ID: 3829952 • Letter: G

Question

GONZO CPP Write a program gonzo.cpp that takes 2 command line input arguments: a number (N) and a name. The program then does 2 things: it prints out what the remainder of N divided by 10 is and, on the next line, prints out the name N times separated by a comma and space character with a period at the end of the sentence. You are only permitted to use the iostream library and you must use a switch statement at least once in this program A session should look exactly like the following example (including whitespace and formatting note that there is no whitespace at the end of each of these lines and each printed line has a newline at the end with all manners of differentnumbers for inputs and the output: ./gonzo 5 jim 5 divided by ten leaves a remainder of five. jim, jim, jim, jim, jim. ./gonzo 53 pam 53 divided by ten leaves a remainder of three. pam, pa pam, pa pam, pa pam, pam, pam, pam, pan, pam, pan, pan, pan, pan, pan pan pa pat pat Pan pat Pan m, Pam, Pam, Pam, Pam, Pam, Pam, Pam, Pam, Pam, Pam, pam, pam, pam, Pam, pam, pam, pam, pam, pam, pam, pam, pam, pam pan, pan, pan, pan, pan, pan ./gonzo 20 dwight 20 divided by ten leaves a remainder of zero. dwight, dwight, dwight, dwight, dwight, dwight, dwight, dwight, dwight, dwight, dwight, dwight, dwight, dwight, dwigh t, dwight, dwight, dwight, dwight, dwight. gonzo 18 michael 18 divided by ten leaves a remainder of eight. michael, michael, michael, michael, michael, michael michael, michael, michael, michael, michael, michael, michael michael, michael, michael michael michael

Explanation / Answer

#include <iostream>
using namespace std;

int myAtoi(char *str)
{
int res = 0; // Initialize result

// Iterate through all characters of input string and
// update result
for (int i = 0; str[i] != ''; ++i)
res = res*10 + str[i] - '0';

// return result.
return res;
}

int main(int argc, char *argv[])
{
int d = myAtoi(argv[1]);

int rem = d%10;

cout << d << " divided by ten leaves a remainder of ";
switch(rem)
{
case 0:
cout << "zero";
break;
case 1:
cout << "one";
break;
case 2:
cout << "two";
break;
case 3:
cout << "three";
break;
case 4:
cout << "four";
break;
case 5:
cout << "five";
break;
case 6:
cout << "six";
break;
case 7:
cout << "seven";
break;
case 8:
cout << "eight";
break;
case 9:
cout << "nine";
break;
  
}
cout << endl;

if (d == 1)
{
cout << argv[2] << "." << endl;
}
else
{
cout << argv[2];
for(int i = 1; i < d; i++)
{
cout << ", " << argv[2];
}
cout << "." << endl;
}


return 0;
}