DOC PREVIEW
CSUN COMP 106 - Homework Solutions

This preview shows page 1-2 out of 5 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 5 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Jacaranda (Engineering) 3333 Mail Code Phone: 818.677.6448E-mail: [email protected] 8348 Fax: 818.677.7062College of Engineering and Computer ScienceComputer Science DepartmentComputer Science 106 Computing in Engineering and ScienceSpring 2006 Class number: 11672 Instructor: Larry CarettoEngineering Building Room 2303 Mail Code Phone: 818.677.6448E-mail: [email protected] 8348 Fax: 818.677.7062March 28 homework solutions Comp 106, L. S. Caretto, Spring 2006 Page 3Homework Solutions – March 28. 2006Page 332, Checkpoint 6.6 – Write a function named timesTen. The function should have an integer parameter named number. When timesTen is called, it should display the product of number times 10. (Note: Just write the function. Do not write a complete program.)void timesTen( int number){cout << “Input number” << number << “ times ten = “ << 10 * number;}Page 332, Checkpoint 6.7 – Write a function prototype for the timesTen function you wrote in question 6.6void timesTen( int Number);Page 332, Checkpoint 6.8 – What is the output of the following program?#include <iostream>using namespace std;void showDouble( int ); // Function prototypeint main(){int num; for ( num = 0; num < 10; num++ ) showDouble( num ); return 0;}// Definition of function showDoublevoid showDouble( int value ){ cout << value << “\t” << ( value * 2 ) << endl;}This program calls the function, void showDouble( int value ), using the following statement: showDouble( num ); this is done inside a for loop where the value of num varies from 0 to 10 in increments of one. Since showDouble prints its input argument and the value of that argument multiplied by two on the same line, the program listed above will print ten lines where the numbers 0 to 9 and the product of those numbers times two are displayed. This program output is shown below:March 28 homework solutions Comp 106, L. S. Caretto, Spring 2006 Page 40 01 22 43 64 85 106 127 148 169 18Page 333, Checkpoint 6.9 – What is the output of the following program?#include <iostream>using namespace std;void func1( float, int ); // Function prototypeint main(){int x = 0;float y = 1.5; cout << x << “ “ << y << endl; func1( y, x ) cout << x << “ “ << y << endl; return 0}void func1( float a, int b ){ cout << a << “ “ << b << endl; a = 0.0; b = 10; cout << a << “ “ << b << endl;}This program prints the values of x and y then calls the function, void func1(float a, int b ), using the following statement func1( y, x ); the subroutine prints the values of a and b then redefines a and b and prints them again. Finally, control is returned to the calling function, main, which prints the values of x and y. The output is shown below with an explanation to the right, written as a C++ comment. 0 1.5 // First line is from main 1.5 0 // Second line is from func1 0 10 // Third line is from func1 0 1.5 // Fourth line is from mainThe first and last line, printed from main have the same values for x and y. The changes to the values of a and b in the function func1 do not affect the values of x and y. This is true because only the values of x and y are passed into the function. The function cannot change these values.The second output line has the values of a and b which are set by the call to func1 from main. The third output line has the values of a and b which are set in the routine.March 28 homework solutions Comp 106, L. S. Caretto, Spring 2006 Page


View Full Document

CSUN COMP 106 - Homework Solutions

Download Homework Solutions
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Homework Solutions and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Homework Solutions 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?