Homework Assignment #6

 

CS 161: Introduction to Computer Science 1

 

 

Submit your Solutions to D2L’s Dropbox

 

 

*** Our objective with homework #6 is to prepare for the final exam and for CS162! ***

 

 

 

For the following questions, write code fragments in C++ that answer the following questions.

 

Write the answers for each of these in C++.

 

Style:

1.      Show a set of code that exhibits three components of good programming style

 

Functions:

2.      Write a prototype for a function called compute. It should have three arguments (an integer, a floating point value, and a single character) all passed by value. It should return nothing.

3.      Write another prototype, but this time it should send all three arguments (an integer, a floating point value, and a single character) all passed by reference. It should return a single character.

4.      Write a function prototype for read_name that has an array of 21 characters as an argument. It should return an integer.

5.      Give an example of a situation where you would want to use pass by reference

6.      Show an example of how a function (such as main) could USE a value returned from a function call (for example, if a function returned an integer – how can the main use that? Show it.)

7.      Write a function named times_ten that takes an integer arumgnet and displays the product of its argument multiplied times 10.

8.      Write a function named get_number which prompts and reads in a number and supplies this information back to the calling routine. Use a returned value.

9.      Rewrite #8 but this time supply the answer back through the argument list.

 

 

Arrays:

10.  Show the variable definitions necessary for holding your name and favorite movie

11.  Prompt the user for your each of the items listed in question #10 and read them in

12.  Show how to capitalize the first character of your name

13.  Now, show how to capitalize the first character of every word in the movie array (The Kings Speech); use a for loop

14.  Show how you could compare the movie to see if it is Matrix

15.  Write ONE if statement to find out if the first letter of the name is between A and Z

16.  Output just the last character of the information stored in an array of characters.

 

General Syntax:

 

17.  Show an example where it would be useful to use cin.ignore(100,’\n’);

18.  Show an example of using string copy from the cstring library

19.  Write a function that reads in someone’s name and salary and supply this information back to the calling routine through the argument list (hint: pass by reference)

20.  Write a do-while loop that calls the function in #17 until the person using the software is satisfied with the information that they entered.

21.  Explain the arguments for the 3 argument version of cin.get