110 likes | 187 Views
Chapter 1 Quiz Questions (CGS-3464). Mahendra Kumar makumar@cise.ufl.edu. Question 1. Which of the following is a valid name for an identifier? interest rate 2fast cout _foobar_2. Question 2. What data types can be used to store numeric values with a decimal point, such as 3.14 ? char
E N D
Chapter 1 Quiz Questions (CGS-3464) Mahendra Kumar makumar@cise.ufl.edu
Question 1 • Which of the following is a valid name for an identifier? • interest rate • 2fast • cout • _foobar_2
Question 2 • What data types can be used to store numeric values with a decimal point, such as 3.14 ? • char • short, int • Long • 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." • cout << "Dan Quayle once said, Who's responsible for the riots? The rioters."; • cout << "Dan Quayle once said, \"Who's responsible for the riots? The rioters. \" "; • cout << "Dan Quayle once said, "Who's responsible for the riots? The rioters. " "; • 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 * 3 + 4 * 5 + 4 / 2; • 11 • 23 • 28 • 14
Question 5 • What value is stored in x after the following two statements are executed: int x; x = 2 / 4 * 4 / 2; • 0.0625 • 1.0 • 1 • 0
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? • 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; • 4 8 • 4 6 • 3 6 • 3 8
Question 8 • How can we input a value from the keyboard and store it in the variable named num? • cin >> num; • cout << num; • num = input(); • cin << num;
Question 9 • Which of the following is an invalid comment? • /* Comment regarding the program */ 2. /************************** * Comment about the program **************************/ • /* 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? • #include<iostream.h> • #include using namespace std; 3. #include<iostream> using namespace std; 4. using namespace std;