Question
Write a function max that has two C string parameters and returns the larger of the two.
Solution
char* max(char *a, char *b)
{
int result = strcmp(a, b);
if (result > 0)
return a;
else
return b;
}
Answers for C++ Course using "Starting out with C++ : from control structures through objects" by Tony Gaddis. 7/8th ed. I used the Pearson myprogramminglab to complete the homework. Here are my solutions/answers for the exercises/labs so please use the test bank as a GUIDE if you're stuck. Let me know if you find a better solution to a problem or any of the programming challenges. Thanks in advance for your support! Send in missing programming challenges to cplusplus.answers@gmail.com
10.4: Library Functions for Working with C-Strings: 10713
Question
Given the char * variables name1 , name2 , and name3 , write a fragment of code that assigns the largest value to the variable max (assume all three have already been declared and have been assigned values).
Solution
max=name1;
if (strcmp(name2, max)>0)
max=name2;
if (strcmp(name3,max)>0)
max=name3;
Given the char * variables name1 , name2 , and name3 , write a fragment of code that assigns the largest value to the variable max (assume all three have already been declared and have been assigned values).
Solution
max=name1;
if (strcmp(name2, max)>0)
max=name2;
if (strcmp(name3,max)>0)
max=name3;
10.3: C-Strings: 10900
Question
Assume that scotus is a two-dimensional character array that stores the family names (last names) of the nine justices on the Supreme Court of the United States. Assume no name is longer than twenty characters. Assume that scotus has been initialized in alphabetical order. Write an expression whose value is the last name stored in the array.
Solution
scotus[8]
Assume that scotus is a two-dimensional character array that stores the family names (last names) of the nine justices on the Supreme Court of the United States. Assume no name is longer than twenty characters. Assume that scotus has been initialized in alphabetical order. Write an expression whose value is the last name stored in the array.
Solution
scotus[8]
10.3: C-Strings: 11122
Question
Declare a char array named line suitable for storing C-strings as large as 50 characters, and write a statement that reads in the next line of standard input into this array. (Assume no line of input is 50 or more characters.)
Solution
char line[50];
cin.getline(line,50);
Declare a char array named line suitable for storing C-strings as large as 50 characters, and write a statement that reads in the next line of standard input into this array. (Assume no line of input is 50 or more characters.)
Solution
char line[50];
cin.getline(line,50);
Exericse Number
11122
Subscribe to:
Posts (Atom)