Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lệnh gán và các tác vụ tăng giảm 1. Bài tập 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Lệnh gán và các tác vụ tăng giảm

1. Bài tập 1

Fill in the blanks to complete the code and outputs

#include < iostream >

using namespace std;

int main()

float radius, height, volume;

radius = 2.5;

height = 32.0;

volume = 3.1416 * radius * radius * height; // assign the expression to volume

cout << "The volume of the cylinder is " << volume << endl;

return 0;

The output of the above program is:

The volume of the cylinder is 628.32

Bài tập 2

Fill in the blanks to complete the code so that the printed results are as expected. The size of each
blank is just 2.

#include < iostream >

using namespace std;

int main()

int num1=10, num2=5, num3=4, num4=6;

num1 += num2;

num2 *= num2;
num4 -= num3;

cout << num1 << num2 << num4;

return 0;

The output of the above program is

15 25 2

2. Bài tập 3

Fill in the blanks so that the printed results are as expected. The size of the blank is 4.

#include < iostream >

using namespace std;

int main()

int a,b,c,d;

a = 1;

b = a++; // The expression contains variable a

c = 3;

d = --c; // The expression contains variable

cout << a << b << c << d;

return 0;

The output of the above code is as follows:

2 122
What library header must be included when function setw() or setprecision() is
used?

string

iostream

iomanip

math.h

Fill in the blanks so that the results are expected

#include < iostream >

#include < iomanip >

using namespace std;

int main()

cout << setw(3) << 6 << endl

<< setw(3) << 18 << endl

<< setw(3) << 124 << endl

<< "---\n"

<< (6+18+124) << endl;

return 0;

The output of the above program:

18

124

---

148
In order to use function sqrt() in the program, which header file must be included in
the beginning of the program?

math.h

iostream

string

stack

Fill in the blanks to make the results as expected.

#include < iostream >


#include < math.h >
using namespace std;
int main(){
float base, exponent, result;
cout << "Enter base and exponent respectively: ";
cin >> base >> exponent;
result = pow(
base
,
exponent
);
cout << base << "^" << exponent << " = " << result;
return 0;
}

Fill in the blanks to make the results as expected.

#include < iostream >

using namespace std;

int main()

float num1, num2, product;

cout << "Please type in a number: ";

cin >> num1;

cout << "Please type in another number: ";

cin >> num2;


product = num1 * num2;

cout << num1 << " times " << num2 << " is " << product << endl;

return 0;

The output of the above program:

Please type in a number: 30

Please type in another number: 0.05

30 times 0.05 is 1.5

Fill in the blanks to make the results as expected.

#include

using namespace std;

int main()

int num1, num2, num3;

float average;

cout << "Enter three integer numbers: ";

cin >>num1>>num2>>num3 ; // there is no space in the blank

average = (num1 + num2 + num3) / 3.0;

cout << "The average of the numbers is " << average << endl;

return 0;

The output of the above program:

Enter three integer numbers: 22 56 73


The average of the numbers: 50.333333

Fill in the blanks so that the printed results as expected.

#include< iostream >

#include< string >

using namespace std;

int main()

string str1; // an empty string

string str2( “Good Morning” );

string str3 = “Hot Dog”;

string str4(str3);// The expression contains variable str3

string str5(str4, 4); // The expression contains variable str4

string str6 = “Linear”;

string str7(str6, 3, 3 ); // The expression contains variable str6

cout << “str1 is: “ << str1 << endl;

cout << “str2 is: “ << str2 << endl;

cout << “str3 is: “ << str3 << endl;

cout << “str4 is: “ << str4 << endl;

cout << “str5 is: “ << str5 << endl;

cout << “str6 is: “ << str6 << endl;

cout << “str7 is: “ << str7 << endl;

return 0;

The output is as follows:

str1 is:
str2 is: Good Morning

str3 is: Hot Dog

str4 is: Hot Dog

str5 is: Dog

str6 is: Linear

str7 is: ear

Fill in the blanks to make the results as expected.

#include< iostream >

#include< string >

using namespace std;

int main()

string str1; // an empty string

cin>>str1; //input string into variable str1

cout << str1 << endl;

return 0;

The input is: Nguyen Van A

The output is: Nguyen

Hãy đọc đoạn văn bên dưới và điền các từ bị thiếu vào chỗ trống.

#include< iostream >

#include< string >

using namespace std;


int main()

string str1; // an empty string

getline(cin,str1); //input string into variable str1

cout << str1 << endl;

return 0;

The input is: Nguyen Van A

The output is: Nguyen Van A

You might also like