CS1336 Ch. 6 Checkpoints

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Write a header for a function named getKey. The function should return a char and use no parameters (6.14)

char getKey()

Write a header for a function named distance. The function should return a double and have two double parameters: rate and time. (6.12)

double distance(double rate, double time)

Is the following a function header or function call? calcTotal(); (6.1)

function call

Is the following a function header or function call? void showResults() (6.2)

function header

Write a header for a function named days. The function should return an int and have three int parameters: years, months, and weeks (6.13)

int days(int years, int months, int weeks)

What kinds of values may be specified as default arguments? (6.19)

literals or constants

Write a header for a function named lightYears. The function should return a long and have one long parameter: miles (6.15)

long lightYears(long miles)

How many return values may a function have? (6.11)

one

What is the difference between a static local variable and a global variable (6.16)

the static local variable has a local scope and can't be used outside the scope, but a global variable can be used throughout the the program

Write the prototype and header for a function called calculate. The function should have three parameters: an int, a reference to a double, and a long (not necessarily in that order.) Only the int parameter should have a default argument, which is 47. (6.21)

void calculate(int = 47, double &, long) void calculate(int x, double &y, long z)

Write the prototype and header for a function called compute. The function should have three parameters: an int, a double, and a long (not necessarily in that order). The int parameter should have a default argument of 5, and the long parameter should have a default argument of 65536. The double parameter should not have a default argument. (6.20)

void compute(int = 5, double, long = 65536); void compute(int x, double y, long z)

Indicate which of the following is the function prototype, the function header, and the function call: void showNum(double num) void showNum(double); showNum(45.67); (6.5)

void showNum(double num) is a function header void showNum(double); is a function prototype showNum(45.67); is a function call

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 ten. (Note: just write the function. Do not write a complete program.) (6.6)

void timesTen (int number) { cout << (number * 10); }

Write a dunction prototype for this function; void timesTen (int number) { cout << (number * 10); } (6.7)

void timesTen(int);

What is the output of the following program? #include <iostream> using namespace std; void myFunc(); // Function prototype int main() { int var = 100 cout << var << endl; myFunc(); cout << var << endl; return 0; } // Definition of function myFunc void myFunc() { int var = 50; cout << var << endl; } (6.17)

100 50 100

What is the output of the following program? #include <iostream> using namespace std; int manip(int); int manip(int, int); int manip(int, double); int main() { int x = 2, y = 4, z; double a = 3.1; z = manip(x) + manip(x, y) + manip(y, a); cout << z << endl; return 0; } int manip(int val) { return val + val *2; } int manip(int val1, int val2) { return (val1 + val2) * 2; } int manip(int val1, double val2) { return val1 * static_cast<int>(val2); }

30

What is the output of the following program? #include <iosteam> using namespace std; void test(int = 2, int = 4, int = 6); int main() { test(); test(6); test(3, 9); test(1, 5, 7); return 0; } void test(int first, int second, int third) { first += 3; second += 6; third += 9; cout << first << " " << second << " " << third << endl; } (6.22)

5 10 15 9 10 15 6 15 15 4 11 16

What will the output of the following program be if the user enters 10? #include <iostream> using namespace std; void func1() { cout << "Able was I\n"; } void func2() { cout << "I saw Elba\n"; } int main() { int input; cout << "Enter a number: "; cin >> input; if (input < 10) { func1(); func2(); } else { func2(); func1(); } return 0; } (6.3)

I saw Elba Able was I

What is the output of the following program? #include <iostream> using namespace std; void func1(double, int) // function prototype int main() { int x = 0; double y = 1.5; cout << x << " " << y << endl; func1(y, x); cout << x << " " << y << endl; return 0; } void func1(double a, int b) { cout << a << " " << b << endl; a = 0.0; b = 10; cout << a << " "<< b << endl; } (6.9)

0 1.5 1.5 0 0 10 0 1.5

What is the output of the following program? #include <iostream> #incliude <cstlib> using namespace std; void showVals(double, double); int main() { double x = 1.2, y = 4.5; showVals(x, y) return 0; } void showVals(double p1, double p2) { cout << p1 << endl; exit(0); cout << p2 << endl; } (6.24)

1.2


संबंधित स्टडी सेट्स

Chapter 15: Crimes of the New Millennium: Cybercrime

View Set

APES Ch.16 renewable energy vocab

View Set

Unit 2: American Revolution & Constitutional Foundations -- Exam

View Set

Web Design Introductory Campbell- Chapter's 3 and 4 Study Guide

View Set

Unit 18 - Speaking In and For Groups

View Set

Chapter 5 - Therapeutic Exercise

View Set

Myers AP Psychology Modules 34, 35, 36

View Set