Some Solutions

Post date: Jan 20, 2013 8:44:45 PM

HW1): write program to compute degree of student.

int x; cin>>x;

if(x>=90)

cout<<"Excellent"<<endl;

else if(x>=80)

cout<<"very.good"<<endl;

else if(x>=70)

cout<<"good"<<endl;

else if(x>=60)

cout<<"fair"<<endl;

else if(x>=50)

cout<<"pass"<<endl;

else cout<<"fail"<<endl;

HW2): write a program in C++ to read three numbers and find the largest.

int x, y, z;

cin>>x>>y>>z;

if ( (x>y) && (x>z) )

cout<<x;

else if ( (y>x) && (y>z) )

cout<<y;

else

cout<<z;

HW3): read a number and print if number more than (0) , print positive else if less than (0), print negative ?

int a; cin>>a;

if(a>0)

cout<<"positive"<<endl;

else

cout<<"negative"<<endl;

HW4):print even & odd?

int x;

cin>>x;

if(x%2==0)

cout<<"even"<<endl;

else

cout<<"odd"<<endl;

HW5):read two number and one character the represent operation to be performed to these number?

void main()

{int d,f;char g;cin>>d>>f>>g;

if(g=='+')cout<<d+f;

else if(g=='-') cout<<d-f;

else if(g=='*')cout<<d*f;

else if(g=='/') cout<<d/f;

else cout<<" Error";

system("pause"); }

HW6): convert integer number to hex & octal?

#include<iostream>

using namespace std;

void main()

{

int k;

cin>>k;

cout<<"hex="<<hex<<k<<endl;

cout<<"octal="<<oct<<k;

}

void main()

{int d,f;char g;

cin>>d>>f>>g;

switch(g)

{case'+':cout<<d+f;break;

case'-':cout<<d-f;break;

case'*':cout<<d*f;break;

case'/':cout<<d/f;break;

default: cout<<"error";

}system("pause"); }