C++ Warm-up Exercises: Input and Output, Boolean Expressions, and Variables, Assignments of Computer Science

C++ warm-up exercises covering various topics such as input and output, boolean expressions, and variables. The exercises include understanding the effect of specific statements, reading data from a file, and evaluating boolean expressions. Students will practice interpreting code and identifying the expected output.

Typology: Assignments

Pre 2010

Uploaded on 08/17/2009

koofers-user-qwv
koofers-user-qwv 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 4 warm up exercises
If input data are
10 20 30 40 50 60
10 20 30 40 50 60
10 20 30 40 50 60
70 80
and the input statements are:
cin >> a >> b >> c;
cin.ignore(100, ‘\n’);
cin.get(ch1);
cin >>d >>e >>f;
cin.ignore(100, ‘\n’);
cin.ignore(100, ‘\n’);
cin >> a >> b;
what is produced by
cout << a <<” “ <<b <<endl;
cout << c <<” “ <<d <<” “<<e<<endl;
cout <<f<<endl;
What is the effect of the following statements?
String coco;
isfstream inFile;
infile.open(“datafile.dat”);
getline(infile, coco);
Suppose a file named bobo.data contains only a collection of whole numbers.
Write the statements necessary to read all the data from the file and output the number of
items in the file.
pf2

Partial preview of the text

Download C++ Warm-up Exercises: Input and Output, Boolean Expressions, and Variables and more Assignments Computer Science in PDF only on Docsity!

Chapter 4 warm up exercises If input data are 10 20 30 40 50 60 10 20 30 40 50 60 10 20 30 40 50 60 70 80 and the input statements are: cin >> a >> b >> c; cin.ignore(100, ‘\n’); cin.get(ch1); cin >>d >>e >>f; cin.ignore(100, ‘\n’); cin.ignore(100, ‘\n’); cin >> a >> b; what is produced by cout << a <<” “ <<b <<endl; cout << c <<” “ <<d <<” “<<e<<endl; cout <<f<<endl; What is the effect of the following statements? String coco; isfstream inFile; infile.open(“datafile.dat”); getline(infile, coco); Suppose a file named bobo.data contains only a collection of whole numbers. Write the statements necessary to read all the data from the file and output the number of items in the file.

Chapter 5 warm up exercises Suppose int1 has the value 12, int2 has the value 18, and int3 has the value 21. What is the result of each of the following boolean expressions? a. int1 < int2 && int2 < int b. int1 > int2 && int2 < int c. int1 > int2 || int2<int d. int1 <= int2 – 6 e. int1++ <= int2 - f. int2 <= int1 + 5 || int3 >= int2 + 5 g. !( int1 < 30 ) h. !(int2 == int1 && int3 > int1) i. !(int1 > 25) && (int1 < 17) Suppose x is of type int, what values of x make the following evaluate to true? ! ((x < 12) || (x >23)) !( x > 5 && x <7 ) What is the value of each of the following? ‘A’ < ‘B’ ‘a’ < ‘b’ ‘a’ < ’B’ Suppose a, b, and x are of type int Which of the following expressions is preferable? a = b/x && x != 0 x != 0 && a = b/x x != 0 || a = b/x