code lab week2

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

A preprocessor directive starts with what character or characters?

#

Write the include directive needed to allow use of the various I/O operators such as cout and cin .

#include <iostream>

Consider Program 2-19 below. Rearrange the lines of code to fix the scope error, yielding a correct C++ program that prints the number 100.

#include <iostream> using namespace std; int main() { int value = 100; cout <<value; return 0; }

Rearrange the following code so that it forms a correct program that prints out the letter Q: int main() } // A SCRAMBLED program return 0; #include <iostream> cout << "Q"; { using namespace std;

#include <iostream> using namespace std; int main() { cout<<"Q"; return 0; }

Write a complete program that prints Hello World to the screen.

#include <iostream> using namespace std; main() { cout <<"Hello World"; return 0; }

Write the necessary preprocessor directive to enable the use of the C++ string class .

#include <string>

Write a character literal representing the digit 1 .

'1'

Write a character literal representing the (upper case) letter A .

'A'

Given an integer variable i and a floating-point variable f, write a statement that writes both of their values to standard output in the following format: i=value -of-i f=value -of-f Thus, if i has the value 25 and f has the value 12.34, the output would be: i=25 f=12.34 But if i has the value 187 and f has the value 24.06, the output would be: i=187 f=24.06

...

Write a floating point literal corresponding to the value zero.

.0

Which of the following lines does NOT consist of (a) valid, though boastful, comment(s)? // /* This is a */ First Rate Program //**// This is a //**// First Rate Program //**// //* This is a //*// First Rate Program //*// /* This is a //*// First Rate Program //*//

/* This is a //*// First Rate Program //*//

A comment starts with what characters?

//

How many spaces printed out by this statement: cout << "how" << "now" << "brown" << "cow" << "?";

0

Write a literal corresponding to the value of the first 6 digits of PI ("three point one four one five nine").

3.14159

How many lines are printed out by this statement: cout << "abc\ndef\tghi\njkl" << endl << endl << "mno\npqr\n";

6

Which of the following is NOT a legal identifier? outrageouslyAndShockinglyLongRunon _42 _ lovePotionNumber9 7thheaven

7thheaven

Which of the following IS a legal identifier? 5_And_10 Five_&_Ten ____________ LovePotion#9 "Hello World"

____________

Write a statement to set the value of ans equal to the value of num plus 5. (These variables have already been declared and num has already been initialized .)

ans = num + 5;

Declare a variable hasPassedTest , and initialize it to true .

bool hasPassedTest=true;

The text of a comment is checked by the compiler for accuracy. must appear in the first line of the program. is printed out when the program runs. can be anything the programmer wants to write.

can be anything the programmer wants to write.

Declare a character variable named c.

char c;

Write a statement to multiply diameter by 3.14159 and assign the result to circumference. (The variables have already been declared and diameter has already been initialized .)

circumference=diameter*3.14159;

Declare an int constant , MonthsInYear , whose value is 12 .

const int MonthsInYear = 12;

Given the variables costOfBusRental and maxBusRiders , write an expression corresponding to the cost per rider (assuming the bus is full).

costOfBusRental/maxBusRiders

Which of the following will not be recognized if iostream is not included in the program? main std namespace return cout

cout

Assume that word is a string variable . Write a statement to display the message "Today's Word-Of-The-Day is: " followed by the value of word on standard output .

cout << "Today's Word-Of-The-Day is: "+word;

Given an integer variable count, write a statement that writes the value of count to standard output .

cout << count;

Assume that message is a string variable . Write a statement to display its value on standard output .

cout << message;

Two variables , num and cost have been declared and given values : num is an integer and cost is a double . Write a single statement that outputs num and cost to standard output . Print both values (num first, then cost), separated by a space on a single line that is terminated with a newline character . Do not output any thing else.

cout <<num <<" "<<cost<<"\n";

Write a statement that prints Hello World to the screen.

cout<<"Hello World";

Declare a numerical variable precise and initialize it to the value 1.09388641.

double precise=1.09388641;

Write a literal representing the false value in C++.

false

Write a declaration for a variable temperature that can hold the current outdoor temperature, measured to the half degree (like 98.6 or 31.5).

float temperature;

Declare a variable x , suitable for storing values like 3.14159 and 6.02E23.

float x;

Given the variables fullAdmissionPrice and discountAmount (already declared and assigned values ), write an expression corresponding to the price of a discount admission. (The variable discountAmount holds the actual amount discounted, not a percentage.)

fullAdmissionPrice - discountAmount

Of the following variable names, which is the best one for keeping track of whether a patient has a fever or not? temperature feverTest hasFever fever

hasFever

Given two integer variables num and highest, write a statement that gives highest the same value that num has.

highest=num;

Write a declaration for two integer variables , age and weight.

int age, weight;

Declare an integer variable named degreesCelsius .

int degreesCelsius;

The exercise instructions here are LONG -- please read them all carefully. If you see an internal scrollbar to the right of these instructions, be sure to scroll down to read everything. Declare and initialize the following variables : A variable monthOfYear , initialized to the value 11 A variable companyRevenue , initialized to the value 5666777 A variable firstClassTicketPrice , initialized to the value 6000 A variable totalPopulation , initialized to the value 1222333

int monthOfYear=11; long companyRevenue=5666777; int firstClassTicketPrice=6000; long totalPopulation=1222333;

Write a declaration of a variable named numberOfWidgets that can be used to hold numbers like 57 and 981 and -4.

int numberOfWidgets;

Write a declaration of a variable named number_of_children that can be used to hold the number of children in a family.

int number_of_children;

Declare a variable populationChange , suitable for holding numbers like -593142 and 8930522.

int populationChange;

Write a statement that declares an int variable presidentialTerm and initializes it to 4.

int presidentialTerm=4;

Which of the following lines contains a valid comment? int twoPi = 3.14159; /* holds the value of two times pi */ int twoPi = 2*3.14159; /* holds the value of two times pi //* int twoPi = 2*3.14159; / / *holds the value of 6 //* double twoPi = 2*3.14159; /* // holds the value of two time pi */ [comment] //

int twoPi = 3.14159; /* holds the value of two times pi */

Which comment below is the most helpful? int volume; // declare an int int volume; // declare volume int volume; // declare volume to be an int variable int volume; // size of trunk in cubic feet

int volume; // size of trunk in cubic feet

Preprocessor directives are carried out just before a program is loaded into the processor. just before a program is executed by the central processing unit (CPU). just before a program is processed by the compiler. just before the program's output is processed.

just before a program is processed by the compiler.

Write a statement to assign to kilos the value of pounds divided by 2.2. (The variables have already been declared and pounds has already been initialized .)

kilos = pounds/2.2;

Every C++ program must contain a ____ function.

main

Which of the following is NOT a C++ keyword? using int main namespace return

main

Of the following variable names, which is the best one for keeping track of whether an integer might be prime or not? divisible isPrime mightBePrime number

mightBePrime

Write a statement to subtract tax from gross_pay and assign the result to net_pay . (The variables have already been declared and gross_pay and tax have already been initialized .)

net_pay=gross_pay-tax;

Write a statement to set the value of num to 4 (num is a variable that has already been declared ).

num=4;

Given the variable pricePerCase , write an expression corresponding to the price of a dozen cases.

pricePerCase * 12

Write an expression that computes the remainder of the variable principal when divided by the variable divisor . (Assume both are type int .)

principal % divisor

An identifier that cannot be used as a variable name is a

reserved word

Write an expression whose value is the number of bytes that an int variable occupies on whatever machine the expression is executed on.

sizeof(int);

The names defined in iostream are associated with which namespace?

std

Declare a string variable named empty and initialize it to the empty string .

string empty="";

Declare a string variable named str and initialize it to Hello .

string str="Hello";

Given three already declared int variables , i , j , and temp , write some code that swaps the values in i and j . Use temp to hold the value of i and then assign j 's value to i . The original value of i , which was saved in temp , can now be assigned to j .

temp=i; i=j; j=temp;

Declare an unsigned integer variable named degreesKelvin .

unsigned int degreesKelvin;

Write an expression that computes the sum of the two variables verbalScore and mathScore (already declared and assigned values ).

verbalScore + mathScore

Assume that an int variable x has already been declared ,. Write an expression whose value is the last (rightmost) digit of x .

x % 10

Assume that an int variable x that has already been declared and initialized . Write an expression whose value is 1 more than x .

x+1


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

Discuter en français - Expressions fréquemment utilisées dans une discussion

View Set

227 Anatomy and Physiology Chapter 27

View Set

POLISCI 110C: America and the World Economy Final Readings

View Set

LS7C - Chapter 9 Cell Signalling

View Set

Chapter 1A Homework: Intro- structural organization, anatomical position, and directional terminology

View Set

Chapter 22 - The Industrial Revolution

View Set

Database Design Chapter 2 Data Models

View Set