Chapter 1 Quiz Questions (CGS-3464) Mahendra Kumar
Question 1 Which of the following is a valid name for an identifier? 1.interest rate 2.2fast 3.cout 4._foobar_2
Question 2 What data types can be used to store numeric values with a decimal point, such as 3.14 ? 1.char 2.short, int 3.Long 4.float, double
Question 3 Which of the following statements will correctly output the quote: Dan Quayle once said, "Who's responsible for the riots? The rioters." 1.cout << "Dan Quayle once said, Who's responsible for the riots? The rioters."; 2.cout << "Dan Quayle once said, \"Who's responsible for the riots? The rioters. \" "; 3.cout << "Dan Quayle once said, "Who's responsible for the riots? The rioters. " "; 4.cout << "Dan Quayle once said, "Who\'s responsible for the riots? The rioters. " ";
Question 4 What value is stored in variable x? int x; x = 2 * * / 2;
Question 5 What value is stored in x after the following two statements are executed: int x; x = 2 / 4 * 4 / 2;
Question 6 Runners often think of their speed in terms of how many minutes and seconds it takes to run a mile, but most treadmills express speed in miles per hour. Which expression correctly converts from 6.5 miles per hour to output the pace in minutes and seconds? 1.int secsPerMile = static_cast int paceMins, paceSecs; paceMins = secsPerMile / 60; paceSecs = paceMin % 60; 2.int secsPerMile = static_cast int paceMins, paceSecs; paceMins = secsPerMile / 60; paceSecs = secsPerMile / 60 / 60; 3. int secsPerMile = static_cast int paceMins, paceSecs; paceMins = secsPerMile / 60; paceSecs = secsPerMile % 60; 4. int secsPerMile = static_cast int paceMins, paceSecs; paceMins = secsPerMile / 60; paceSecs = secsPerMile % 60;
Question 7 What will the following code output? int x, y; x=3; y=(++x)*2; cout << x << " " << y << endl;
Question 8 How can we input a value from the keyboard and store it in the variable named num? 1.cin >> num; 2.cout << num; 3.num = input(); 4.cin << num;
Question 9 Which of the following is an invalid comment? 1./* Comment regarding the program */ 2./************************** * Comment about the program **************************/ 3./* Comment regarding the program 4.// Comment regarding the program
Question 10 For a newer C++ compiler, what must be added to the top of the program to allow access to cin and cout? 1.#include 2.#include using namespace std; 3.#include using namespace std; 4.using namespace std;