Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Problem 16

Write a program that demonstrates passing an array by value. [Hint: Use a struct.] Prove that a copy was passed by modifying the array copy in the called function.

Problem 18

The following program uses function multiple to determine whether the integer entered from the keyboard is a multiple of some integer \(x\). Examine function multiple, then determine the value of \(x\). 1 // Exercise 22.19: ex22_19.cpp 2 // This program determines if a value is a multiple of X. 3 #include 4 5 using std::cout; 6 using std::cin; 7 using std::endl; 8 9 bool multiple( int ); 10 11 int main() 12 { 13 int y; 14 15 cout << "Enter an integer between 1 and 32000: "; 16 cin >> y; 17 18 if ( multiple( y ) ) 19 cout << y << " is a multiple of X" << endl; 20 else 21 cout << y << " is not a multiple of X" << endl; 22 23 return 0; 24 25 } // end main 26 27 // determine if num is a multiple of X 28 bool multiple( int num ) 29 { 30 bool mult = true; 31 32 for ( int i = 0, mask = 1; i < 10; i++, mask <<= 1 ) 33 34 if ( ( num & mask ) != 0 ) { 35 mult = false; 36 break; 37 38 } // end if 39 40 return mult; 41 42 } // end function multiple

Problem 23

Write a program that inputs a line of text and a search string from the keyboard. Using function strstr, locate the first occurrence of the search string in the line of text, and assign the location to variable searchPtr of type char \(* .\) If the search string is found, print the remainder of the line of text beginning with the search string. Then use strstr again to locate the next occurrence of the search string in the line of text. If a second occurrence is found, print the remainder of the line of text beginning with the second occurrence. [Hint: The second call to strstr should contain the expression searchPtr +1 as its first argument.

Problem 25

Write a program that inputs several lines of text and a search character and uses function strchr to determine the total number of occurrences of the character in the lines of text.

Problem 28

Write a program that reads a series of strings and prints only those strings beginning with the letter "b."

Problem 29

Write a program that reads a series of strings and prints only those strings that end with the letters "ED."

Problem 30

Write a program that inputs an ASCII code and prints the corresponding character. Modify this program so that it generates all possible three-digit codes in the range 000255 and attempts to print the corresponding characters. What happens when this program is run?

Access millions of textbook solutions in one place

  • Access over 3 million high quality textbook solutions
  • Access our popular flashcard, quiz, mock-exam and notes features
  • Access our smart AI features to upgrade your learning
Get Vaia Premium now
Access millions of textbook solutions in one place

Recommended explanations on Computer Science Textbooks