3
5
Tong cua 3 va 5 la 8.
Trung binh cong cua 3 va 5 la 4.
Request:
Suppose an automobile has initial velocity v 0 , acceleration a and time t. Write a C ++ program to find the final speed of the car and print the results to the screen.
Suggestions:
Sample code:
#include #include using namespace std; int main() { int v,u,a,t; cout << "Nhap van toc v0, gia toc a, thoi gian t: " << endl; cin>>u>>a>>t; v=u+a*t; cout << "Van toc cuoi cung la " << v << "." << endl; return 0; }
Result:
Nhap van toc v0, gia toc a, thoi gian t:
10 2 15
Van toc cuoi cung la 40.
Request:
Write a C ++ program to print the results as follows:
Gtri x Gtri y Bieu Thieu Thuc Ket 18 | 2 | A = y + 3 | A = 5 18 | 2 | B = y-2 | B = 0 18 | 2 | C = y * 5 | C = 10 18 | 2 | D = x / y | D = 9 18 | 2 | E = x% y | E = 0Suggestions:
Sample code:
#include #include using namespace std; int main(int argc, char *argv[]) { int x; int y; x=18; y=2; cout<<"Ket qua tra ve:n"; cout<<"Gtri xt"<<"Gtri yt"<<"Bieu thuct"<<"Ket quan"; cout<
Result:
Request:
Write a program to enter midterm test scores, test scores, final exam scores, then calculate the total score and print the results to the screen as follows:
Sample code:
#include #include #include using namespace std; int main(int argc, char *argv[]) { float q1; float q2; float q3; float tongdiemkt; float diemgk; float diemck; float tongdiem; cout<<"==========Diem kiem tra================n"; cout<<"Nhap diem kiem tra 1:"; cin>>q1; cout<<"n"; cout<<"Nhap diem kiem tra 2:"; cin>>q2; cout<<"n"; cout<<"Nhap diem kiem tra 3:"; cin>>q3; cout<<"n"; cout<<"==========Diem thi giua ky=============n"; cout<<"Nhap diem thi giua ky:"; cin>>diemgk; cout<<"n"; cout<<"===========Diem thi cuoi ky=============n"; cout<<"Nhap diem thi cuoi ky:"; cin>>diemck; cout<<"n"; tongdiemkt=q1+q2+q3; tongdiem=tongdiemkt+diemgk+diemck; cout<<"Tong diem kiem tra:"<
Result:
Request:
Write a C ++ program to enter two integers x, y, then calculate: p = x * y, s = x + y, q = s 2 + p (sx) * (p + y) and print the results to the screen form.
Sample code:
#include #include #include using namespace std; int main(int argc, char *argv[]) { float x; float y; float p; float s; float q; cout<<"Nhap gia tri x: "; cin>>x; cout<<"n"; cout<<"Nhap gia tri y: "; cin>>y; cout<<"n"; p=x*y; s=x+y; q=s*s+p*(sx)*(p+y); cout<<"Gia tri bieu thuc q la: "<
Result:
Nhap gia tri x: 5
Nhap gia tri y: 10
Gia tri bieu thuc q la: 30225
Request:
Use the concept of overloading operators to add and subtract two complex numbers.
Suggestions:
To use operator overloading in this addition and subtraction problem, you need to do the following:
Declaring the sophuc class: Include variables and member functions
Use the getvalue () function to get the real part, the virtual part of the complex number
Define operator + () function to add two complex numbers
Define operator- () function to subtract two complex numbers
Definition of display function
Declare complex numbers i1, i2 and calculation results kq1, kq2
Call the getvalue function to get the real part and the virtual part for i1, i2
Call the function operator + () and operator- () to add and subtract two complex numbers
Calling the display function to display 2 complex numbers, 2 results plus and minus
Returns values
Sample code:
#include #include using namespace std; class sophuc { int a,b; public: void getvalue() { cout<<"Hãy nhập phần thực, phần ảo:"; cin>>a>>b; } sophuc operator+(sophuc i) { sophuc q; qa=a+ia; qb=b+ib; return(q); } sophuc operator-(sophuc i) { sophuc q; qa=ai.a; qb=bi.b; return(q); } void display() { cout<
Result: