You are on page 1of 2

CODE: CPP.Assignment01.

Opt1 FRESHER
Assignment topic : Variables and Data Types
ACADEMY
Assignment duration : 180 minutes

Bài 1: Thực hiện các bước sau:

- Create a variable named myNum and assign the value 50 to it


o int myNum = 50;
- Create a variable named myNum1, assign the value 19 to it and add it to MyNum
o int myNum1 = 19;
o int MyNum;
o MyNum+=myNum1;
- Create two variables named numX and numY, assign the value X to it and add it to MyNum such
that MyNum equal to maximum range of Short Int and assign the value Y to it and add it to
MyNum1 such that MyNum1 equal to minimum range of Short Int. Find X, Y
o int numX, numY;
o myNum = myNum + myNum1;
o numX = 32767- myNum;
o numY= -32767 - myNum1;
o cout<<”X la: “<<numX<<endl;
o cout<<”Y la: “<<numY<<endl;

Bài 2: Add the correct data type for the following variables:

___ myNum = 1; (char, unsigned char, signed char, int, unsigned int, short, unsigned short, long,
unsigned long)

___ myNum1 = 10001; (int, unsigned int, short, unsigned short, long, unsigned long)

___ myNum2 = 100000001; (int, unsigned int , long, unsigned long)

___ myNum3 = 10000000000001; (long long)

___ myNum4 = -10000000000001; (signed long long)

___ myDoubleNum = 1.001; (float, double)

___ myDoubleNum1 = 100000000000001.100001; (long long double)

___ myDoubleNum2 = -1000000001.100001; (double, long double)

___ myLetter = 'A'; (char, string[1])

___ myLetter1 = "c"; (char[1], string)


___ myText = "Hello World"; (string)

___ myBool = false; (bool, boolean)

Bài 3: Tạo file Exercise.cpp: Viết chương trình in ra màn hình console tên, tuổi, điểm tổng kết (float,
double) của bản thân trên mỗi dòng riêng biệt.
#include<iostream>
#include <string>
using namespace std;

int main() {

cout << "<---------------------------------------------------->" << endl;


cout << " Ten sinh vien: Vu Van Minh." << endl;
cout << "<---------------------------------------------------->" << endl;
cout << " Nam nay 22 tuoi." << endl;
cout << "<---------s------------------------------------------>" << endl;
cout << " Diem tong ket: 9.0" << endl;
cout << "<---------------------------------------------------->" << endl;
return 0;
}

Bài 4. Liệt kê các kiểu dữ liệu


Kiểu dữ liệu Size (byte) Phạm vi
char 1 -127 tới 127 hoặc 0 tới 255
unsigned char 1 0 tới 255
signed char 1 -127 tới 127
int 4 -2147483648 tới 2147483647
unsigned int 4 0 tới 4294967295
signed int 4 -2147483648 tới 2147483647
short 2 -32,768 tới 32,767
short int 2 -32768 tới 32767
-2,147,483,648 tới
long 4
2,147,483,647
float 4 +/- 3.4e +/- 38
double 8 +/- 1.7e +/- 308
bool 1 0, 1

You might also like