Unformatted text preview:

1 Determine the value of d double d 11 2 5 2 Determine the value of pow 2 3 8 fabs 3 5 3 5 sqrt pow 3 2 3 7 abs 2 3 ceil 5 8 6 floor 5 8 5 3 Convert the following to C statements x 1 sqrt x 1 b b 2 4ac 2a b sqrt b b 4 a c 2 a x y 7 pow x y 7 4 Write a function declaration and a function definition for a function that takes three arguments all of type int and that returns the sum of its three arguments int sumOfThree int x int y int z int sumOfThree int x int y int z calculate the sum and return the value return x y z 5 Write a function declaration and a function definition for a function that takes one argument of type int and one argument of type double and that returns a value of type double that is the average of the two arguments 6 Describe the differences between void functions and functions that return one value Void functions are created and used just like value returning functions except they do not return a value after the function executes Keyword void replaces the type of the value returned void means that no value is returned by the function The return statement does not include and expression 7 What happens if you forget the return statement in a void function Because the main function is defined to return a value of type int the return is needed n C standard says the return 0 can be omitted but many compilers still require it 8 Describe the differences between functions that are used as expressions and those used as statements Expression Something which evaluates to a value Example 1 2 x Statement A line of code which does something Example GOTO 100 9 Write a void function definition for a function called zero both that has two reference parameters both of which are variables of type int and sets the values of both variables to 0 void zero both int n1 int n2 n1 0 n2 0 10 Can you define a function in the body of another function No a function definition cannot appear inside the body of another function definition 11 Can you call one function from the body of another function Yes a function definition can contain a call to another function 12 Give preconditions and postconditions for the predefined function sqrt double sqrt double n Precondition n 0 Postcondition Returns the square root of n 13 Describe what it means to say a programmer should be able to treat a function as a black box the programmer should not need to look at the body of the function definition to see how the function works The function declaration and accompanying comment should be all the programmer needs to know in order to use the function 14 Describe what it means for two functions to be black box equivalent the function would return the same value in either case so the two definitions are black box equivalent 15 Name at least three member functions of an iostream object and give examples of usage of each open close fail int c ifstream in ofstream out in open in dat if in fail cout Input file failed end exit 1 out close in close 16 Write a program that uses a stream called fin which will be connected to an input file and a stream called fout which will be connected to an output file include fstream ifstream fin ofstream fout using namespace std 17 Show the output produced when the following line is executed cout setw 3 12345 endl 12345 18 Describe the effect of each of these flags Ios fixed Setting this causes floating point numbers not to be displayed in e notation it unsets ios scientific ios scientific Setting this causes floating point numbers to be displayed in e notation ios showpoint Setting this causes the decimal point and trailing zeros to be always displayed ios left Setting this causes subsequent output to be placed at the left end of any field that is set with the width member function It unsets ios right ios right Setting this causes subsequent output to be placed at the right end of any field that is set with the width member function ios showpos Setting this causes a plus sign to be displayed before positive integer values 19 Write code that will read a line of text and echo the line with all the uppercase letters deleted cout Enter a line of input n char next do cin get next if isupper next cout next while next n 20 Describe two methods to detect the end of an input file eof that returns non zero meaning TRUE when there are no more data to be read from an input file stream and zero meaning FALSE otherwise while inFile eof


View Full Document

UCSB CS 16 - Determine the value of d

Documents in this Course
Load more
Loading Unlocking...
Login

Join to view Determine the value of d 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 Determine the value of d 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?