Lab 2
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
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;
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;
}