C++ Functions

20 Questions | Attempts: 3950
Share

SettingsSettingsSettings
C++ Functions - Quiz

In order to learn how to use and write functrions in C++ we must fist start by knowing some of the words. This quiz provides you with a different way of learning the terms so that you can read the questions that you will have on the test and final exam.


Questions and Answers
  • 1. 
    In the following declaration, what is the return type?int myMethod(int count, double value) {    return 4;}
    • A. 

      Int

    • B. 

      MyMethod

    • C. 

      4

    • D. 

      Double

    • E. 

      Count

  • 2. 
    In the following function declaration, what is the name of the method?void showMenu(string category) {}
    • A. 

      Void

    • B. 

      ShowMenu

    • C. 

      String

    • D. 

      Category

  • 3. 
    In the following functiondeclaration, how many formal parameters are there?double squareRoot(double value) {  return 2.3;}
    • A. 

      Double

    • B. 

      Value

    • C. 

      1

    • D. 

      2

  • 4. 
    In the following function how many values are returned?void syncPhone(int idNumber) {}
    • A. 

      0

    • B. 

      1

    • C. 

      2

  • 5. 
    What word is missing below (fill in the __________).   Write a function declaration called increaseTemperature which takes 2 integers as a formal parameters.  The two parameters represent the upper and lower targets.  The function returns the different between the upper and lower targets as an integer._________  increaseTemperature(int upper, int lower) {    return upper - lower;}
  • 6. 
    Write a function declaration for the following description (just the first line).  The wording must be exact and correct!The method must be called calculateFinalExam.  The method must return a double.  The method accepts 3 parameters:1. the studentId which must be an integer2. the studentName which must be a String3. the testScore which must be a double.
  • 7. 
    What is the output of this main() method?  Put the letters into the answer box provided wih no spaces between (i.e. ABCEDFG)void showMenu() {    cout << "Q";}void eraseFile() {   cout << "T";}void processRequest() {  cout << "2";} int main(int argc char *argv[]) {     cout << "A";     processRequest();     cout << "B";     cout << "C";     showMenu();     cout << "D";}
  • 8. 
    What is the output of this program?  Put the letters into the answer box provided wih no spaces between (i.e. ABCEDFG)void showMenu() {    cout << "Q";}void eraseFile() {   cout << "T";}public static void processRequest() {  cout << "2";} int main(int argc, char *argv[]) {     cout << "A";     processRequest();     processRequest();     showMenu();     eraseFile();     cout << "B";}
  • 9. 
    What is the output of this main() method?  Put the letters into the answer box provided wih no spaces between (i.e. ABCEDFG)int main(int argc, char *argv[]) {     showMenu();     eraseFile();     cout << "B";     showMenu();}void showMenu() {    cout << "Q";    eraseFile();}void eraseFile() {   cout << "T";}void processRequest() {  cout << "2";}
  • 10. 
    What is the output of this main() method?  Put the letters into the answer box provided wih no spaces between (i.e. ABCEDFG)int getRemoteId() {   return 3;}int getMonitorCount() {  return 2;}int getStudentCount() {  return 6;}int main(int argc, char *argv[]) {    int value;    cout << "@";    v = getRemoteId();    cout << v;    cout << "E";    v = getStudentCount();    cout << v;    cout << "F";    v = getMonitorCount();    cout << "W";    }
  • 11. 
    The following code in the main is valid:void createGameCharacter() {}int main(int argc, char *argv[]) {    int value;    value = createGameCharacter();    // rest of program}
    • A. 

      True

    • B. 

      False

  • 12. 
    The following code in the main is valid:int depositMoney() {   return 4;}int main(int argc, char *argv[]) {    int value;    value = depositMoney(amount);    // rest of program}
    • A. 

      True

    • B. 

      False

  • 13. 
    What is the output of this main() method?  Put the letters into the answer box provided wih no spaces between (i.e. ABCEDFG)void loadSong(int id) {   cout << id;}int checkLength(int id) {  cout << id;  id = id + 4;  cout << id;  return 9;}int getStudentCount() {  return 6;}int main(int argc, char *argv[]) {    int value;    loadSong(5);    cout << "A";    value = checkLength(1);    cout << "B";    cout << value;    value = checkLength(4);}
  • 14. 
    What is the output of this main() method?  Put the letters into the answer box provided wih no spaces between (i.e. ABCEDFG)void loadSong(int id) {   cout << id;}int checkLength(int id) {  cout << id;  id = id + 4;  cout << id;  return 9;}int getStudentCount() {  return 6;}int main(int argc, char *argv[]) {    int value;    int x;    x = 3;    cout << "A";    value = checkLength(x);    cout << "B";    cout << x;    cout << value;}
  • 15. 
    What is the output of this main() method?  Put the letters into the answer box provided wih no spaces between (i.e. ABCEDFG)void showValues(int x, int y) {   cout << x;   cout << y;   x = 4;}int checkLength(int id) {  cout << id;  id = id + 4;  cout << id;  return 9;}int getStudentCount() {  return 6;}int main(int argc, char *argv[]) {    int x;    int y;    x = 1;    y =  2;    showValues(y, x);    cout << x;    cout << y;}
  • 16. 
    When the changeChannel() method is called below, what is the value of the parameter number?void changeChannel(int number) {   // code is hidden} int main(int argc, char *argv[]) {    int ch;   ch = 240;   changeChannel(ch + 10);}
  • 17. 
    To call the function startCall() with the number 4432 and 3 retries what would you write in the main() function? Remember to put a ; at the end of the statement.void startCall(int number, int retries){   // code is hidden}
  • 18. 
    What is the value that is returned in the following function?int getVolume() {   int v;   v = 23;   if (v < 50) {      return 50;   }   return v;}
    • A. 

      50

    • B. 

      23

    • C. 

      50 and 100

    • D. 

      150

  • 19. 
    What is the output of the following program?int getFirstDigit(int value) {   return value/10;}int getLastDigit(int value) {  return value % 10;} int main(int argc, char *argv[]) {    int x;    int first;    int second;    x = 42;    first = getFirstDigit(x);    second = getSecondDigit(x);    cout << second;    cout << first;}
  • 20. 
    True or False. The call to the function installApplication() is valid:void installApplication(string appName, int appVersion) {  // rest of method not important} int main(int argc, char *argv[]) {   installApplication("Angry Birds", "version 1.2");}
    • A. 

      True

    • B. 

      False

Back to Top Back to top
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.