CIS 1033 - Fundamentals of Programming

Bob Comer, Professor, CIS/CSC


Chapter 6 Homework
Due Wednesday, June 30

Click here for answers.

  1. Modify the following program so that the mileage (miles per gallon) calculation is done in a value-returning function. Call your function directly in the last cout statement of the program. Delete the milesPerGallon variable from the main() function (you will not need it).
  2. int main()
    {
       int startMiles, endMiles;
       float gallons, milesPerGallon;
    
       cout << "Enter starting and ending mileage: ";
       cin >> startMiles >> endMiles;
       cout << "Enter gallons of gas used: ";
       cin >> gallons;
    
       milesPerGallon = (endMiles - startMiles) / gallons;
    
       cout << "Your mileage is " << milesPerGallon
            << " miles per gallon" << endl;
    
       return 0;
    }
  3. Write a possible prototype for function Func() below.
  4. int main()
    {
       double d;
       float f = 6.2;
       int i = 3;
       d = Func( i, f );
       cout << "The result is " << d << endl;
       return 0;
    }
  5. Write an example call for the following function.
  6. float square( float num)
    {
       return num * num;
    }
  7. True or False: To use a constant variable throughout your program, it should be declared inside your main() function.
  8. Write a function that receives a float parameter called num and calculates and returns the fourth power of num (num * num * num * num). Try using a local variable in your function.
  9. Write a function that prints the sentence:

    Your age is ___ years.

    In the blank space in the sentence it should print the value of an nteger parameter called age.
  10. Write a function that prompts the user to enter a number of hours worked and a pay rate. Your function should then input two values into float parameters called hoursWorked and payRate. Your function will need to supply the two input values to the calling function.
  11. The following program will not compile. Find the problem and fix it.
  12. #include <iostream.h>
    
    void PrintCurved( int grade );
    
    int main()
    {
       int studentNo, grade;
       cout << "Enter student number and grade:";
       cin >> studentNo >> grade;
       PrintCurved(grade);
       return 0;
    }
    
    void PrintCurved( int grade )
    {
       cout << "The curved grade for student ";
            << studentNo << " is " 
            << grade + 10 << endl;
    }
  13. Write a function that receives two float values as parameters and "returns" each value halved. Write an example call for your function. Write declarations for all variables that you use.


Return to Fundamentals Home Page

URL: http://www.austin.cc.tx.us/comer/cis1033/
Copyright: Ó 1999 by the Austin Community College
Department of Computer Studies. All rights reserved.
Comments to: Bob Comer
Last updated: April 4, 1999

Austin Community College is an equal opportunity educator and employer.