180 likes | 192 Views
LAB # 8. What is output by the following program segment when function f1 is invoked?. 10 5. What is the output of cout << mystery( 6, 2, 5 ) << endl ; assuming the following definition of mystery?. 6. What is output by the following program?. Initially, x = 0 During call to f1, x = 3
E N D
What is output by the following program segment when function f1 is invoked? 10 5
What is the output ofcout << mystery( 6, 2, 5 ) << endl;assuming the following definition of mystery? 6
What is output by the following program? Initially, x = 0 During call to f1, x = 3 At the end, x = 0
Determine if there is an error in the code, and specify whether it is a logic or compilation error Line 1: Placing a semicolon at the end of the parameter list of a function definition results in a compilation error.
Determine if there is an error in the code, and specify whether it is a logic or compilation error void f1(); Line 7: There is no function prototype for function f1 and it is defined below the main function. Therefore, when compiling this program, a compilation error will occur because the function is not declared before it is used.
Determine if there is an error in the code, and specify whether it is a logic or compilation error Line 5: You cannot define a function inside of another function. This is a syntax error.
Write a program that prints the square roots of the numbers 0 through 5.
Write a program with a function named fact() to find the factorial from 0 to the number that reads from the user. Enter the number 4 fact(0) = 1 fact(1) = 1 fact(2) = 2 fact(3) = 6 fact(4) = 24
Write a program consists of 3 functions as follows: • v_swapfunction • Has no return value • Takes two parameters of type int(pass by value) • Swaps the value of the two variables • displays the variables after swapping. • r_swap function • Same as v_swap but the parameters pass by reference • the main function: • Declares and initiates two int variables • Calls v_swap • Displays the two variables • Calls r_swap • Displays the two variables
#include<iostream> • using namespace std; • void v_swap(int , int ); • void r_swap(int &, int &); • void main() • { • int x = 11, y = 22; • cout << "Before calling any function, x = "<< x <<" y = "<< y << endl; • v_swap( x, y); • cout << "After calling v_swap, x = "<< x <<" y = "<< y << endl; • r_swap( x, y); • cout << "After calling r_swap, x = "<< x <<" y = "<< y << endl; • } • void v_swap(int x, int y) • { • int temp = x; • x = y; • y = temp; • cout << "Inside the function v_swap, x = "<< x <<" y = "<< y << endl; • } • void r_swap(int &x, int &y) • { • int temp = x; • x = y; • y = temp; • cout << "Inside the function r_swap, x = "<< x <<" y = "<< y << endl; • }
Header File fac.h
Source File main.cpp