0% found this document useful (0 votes)
24 views

Lab 2

Uploaded by

pxhuy2006
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Lab 2

Uploaded by

pxhuy2006
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

LAB 2

Exc 3:
#include <iostream>
using namespace std;

int main() {
// Variable declarations
int units; // to store the number of units
double price; // to store the price per unit
int idnumber; // to store the ID number
double cost; // to store the total cost
double tax; // to store the tax amount
double total; // to store the final total amount

// Assign values to variables


units = 5;
price = 12.5;
idnumber = 12583;
cost = price * units;

// Display product details


cout << idnumber << " " << units << " " << price << " " << cost << endl;

// Calculate tax and total


tax = cost * 0.06;
total = cost + tax;

// Display tax and total


cout << tax << " " << total << endl;

return 0;
}

Exc 4:
#include <iostream>
using namespace std;

int main()
{
int a,b,c;
cout<<"Type a: ";
cin>>a;
cout<<"Type b: ";
cin>>b;
c=a;
a=b;
b=c;
cout<<"a is "<< a<<endl;
cout<<"b is "<< b;
return 0;
}

Exc 5:
#include <iostream>
#include <string>
using namespace std;

int main() {
string name;
int age;
char sex;
float height, weight;

// Reading data from the user


cout << "Enter Name: ";
getline(cin, name);
cout << "Enter Age: ";
cin >> age;
cout << "Enter Sex (M/F): ";
cin >> sex;
cout << "Enter Height (in cm): ";
cin >> height;
cout << "Enter Weight (in kg): ";
cin >> weight;

// Displaying the collected information with proper headings


cout << "\n--- Student Information ---" << endl;
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
cout << "Sex: " << sex << endl;
cout << "Height: " << height << " cm" << endl;
cout << "Weight: " << weight << " kg" << endl;

return 0;
}

Exc 6:
#include <iostream>
#include <cmath>
using namespace std;

int main() {
double r;
cout << "Enter the radius: ";
cin >> r;
double C = 2 * M_PI * r;
cout << "The circumference is: " << C << endl;

return 0;
}

Exc 7:
#include <iostream>
using namespace std;

int main()
{
double f,c;
cout<<"Type the number off F degree: ";
cin>>f;
c = (5.0/9)*(f - 32);
cout<<"The C degree is: "<<c;
return 0;

}
Exc 8:
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
int a,b,c,d;
cout << "Enter A(a,b): "<<endl;
cout << "a: ";
cin >> a;
cout << "b: ";
cin >> b;
cout << "Enter B(a,b): "<<endl;
cout << "c: ";
cin >> c;
cout << "d: ";
cin >> d;
cout << "The distances between A and B is: " << sqrt(pow(a-c,2)+pow(b-d,2)) <<
endl;

return 0;
}

You might also like