6.4: Sending Data into a Function

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

printErrorDescription is a function that accepts one int parameter and returns no value . Write a statement that calls the function printErrorDescription, passing it the value 14.

printErrorDescription(14);

printLarger is a function that accepts two int parameters and returns no value . Two int variables , sales1 and sales2, have already been declared and initialized . Write a statement that calls printLarger, passing it sales1 and sales2.

printLarger(sales1, sales2);

Write the definition of a function dashedLine, with one parameter , an int . If the parameter is negative or zero, the function does nothing. Otherwise it prints a complete line terminated by a new line character to standard output consisting of dashes (hyphens) with the parameter 's value determining the number of dashes. The function returns nothing.

void dashedLine(int n) { if(n > 0) cout << string(n,'-') << endl; }

Write the definition of a function printAttitude, which has an int parameter and returns nothing. The function prints a message to standard output depending on the value of its parameter . If the parameter equals 1, the function prints disagree If the parameter equals 2, the function prints no opinion If the parameter equals 3, the function prints agree In the case of other values , the function does nothing. Each message is printed on a line by itself.

void printAttitude (int a) { switch(a) { case 1: cout << "disagree"<<endl; break; case 2: cout << "no opinion"<<endl; break; case 3: cout << "agree"<<endl; break; } }

Write a statement that declares a prototype for a function printErrorDescription, which has an int parameter and returns nothing.

void printErrorDescription(int);

Write the definition of a function printGrade, which has a char parameter and returns nothing. The function prints on a line by itself the message string Grade: followed by the char parameter (printed as a character ) to standard output . Don't forget to put a new line character at the end of your line. Thus, if the value of the parameter is 'A', the function prints out Grade: A

void printGrade(char c) { printf("Grade: %c\n",c); }

Write the definition of a function printLarger, which has two int parameters and returns nothing. The function prints the larger value of the two parameters to standard output on a single line by itself. (For purposes of this exercise, the "larger " means "not the smaller".)

void printLarger ( int a , int b ) { if ( a > b ) cout << a << endl ; else cout << b << endl ; }

Write a statement that declares a prototype for a function printLarger, which has two int parameters and returns no value .

void printLarger(int, int);


Set pelajaran terkait

Algebra Chapter 10 Test Review - Radicals

View Set

American Government and Politics

View Set

MKT 365 Chapter 8 (Inventory Management)

View Set

Chapter 12 - Imports, Customs, and Tariff Law

View Set

chapter 10- human resources management

View Set

Clinical Applications of Gas Laws Workshop

View Set

Chapter 12 Intermediate Accounting

View Set