Robert Lafore C++,solved Exercise Problems, Chapter-2
Robert Lafore C++,solved Exercise Problems, Chapter-2
Chapter 2
Answer to the question number-1
The code segment:
#include<iostream>
#include <iomanip>
using namespace std;
int main()
{
double g;
cout<<"Enter the numbers in Gallons:"<<endl;
cin>>g;
cout<<g/7.481<<" cubic feets"<<endl;
}
Answer to the question number-2
The code segment:
#include<iostream>
#include <iomanip>
using namespace std;
int main()
{
double g;
cout<<setw(4)<<1990<<setw(12)<<135<<endl
<<setw(4)<<1991<<setw(12)<<7290<<endl
<<setw(4)<<1992<<setw(12)<<11300<<endl
<<setw(4)<<1993<<setw(12)<<16200<<endl;
}
Answer to the question number-3
The code segment:
#include<iostream>
#include <iomanip>
#include <ios>
using namespace std;
int main()
{
int x=10;
cout<<x<<endl;
x=20;
cout<<x<<endl;
--x;
cout<<x<<endl;
}
}
Answer to the question number-9
The code segment:
#include<iostream>
#include <iomanip>
#include <ios>
using namespace std;
int main()
{
int a,b,c,d;
char j;
cout<<"Enter first fraction: "<<endl;
cin>>a>>j>>b;
cout<<"Enter second fraction: "<<endl;
cin>>c>>j>>d;
int m=(a*d)+(b*c);
int k=b*d;
cout<<"Sum= "<<m<<'/'<<k<<endl;
}
}
Answer to the question number-11
The code segment:
#include <ios>
#include<bits/stdc++.h>
using namespace std;
int main()
{
double user;
cout<<"Enter decimal pounds:"<<endl;
cin>>user;
int j=user;
cout<<"Equivalent in old notation = "<<'\x9c'<<j<<".";
double frac=user-j;
frac*=20;
int newfrac=frac;
cout<<newfrac<<".";
frac=frac-newfrac;
frac*=12;
frac=(int) frac;
cout<<frac<<"."<<endl;