Sunday, January 24, 2016

C++ operators (con)

1. Write a C++ program to generate the results as shown below: Results:   =======Quizzes=============== Enter the score of the first quiz:... thumbnail 1 summary

1. Write a C++ program to generate the results as shown below:

Results: =======Quizzes===============
Enter the score of the first quiz: 90
 
Enter the score of the second quiz: 75
 
Enter the score of the third quiz: 91
 =======Mid-term============== 
Enter the score of the mid-term: 80
 
=======Final=================
 
Enter the score of the final: 89
   
Quiz Total:      256
 
Mid-term :       80
 
Final        :       89
 
……………………
 
Total:               425

Solution:

 #include <cstdlib> 
#include <iostream> 
#include<iomanip> 
using namespace std; 
int main(int argc, char *argv[]) 
{ 
    float q1; 
    float q2; 
    float q3; 
    float qtotal; 
    float midterm; 
    float final; 
    float total; 
    cout<<"==========QUIZZES================\n"; 
    cout<<"Enter the score of the first quizz:"; 
    cin>>q1; 
    cout<<"\n"; 
    cout<<"Enter the score of the second quizz:"; 
    cin>>q2; 
    cout<<"\n"; 
    cout<<"Enter the score of the third quizz:"; 
    cin>>q3; 
    cout<<"\n"; 
    cout<<"==========MID-TERM==============\n"; 
    cout<<"Enter the score of the mid-term:"; 
    cin>>midterm; 
    cout<<"\n"; 
    cout<<"===========FINAL================\n"; 
    cout<<"Enter the score of the final:"; 
    cin>>final; 
    cout<<"\n"; 
    qtotal=q1+q2+q3; 
    total=qtotal+midterm+final; 
    cout<<"Quizz Total:"<<right<<setw(5)<<qtotal; 
    cout<<"\n"; 
    cout<<"Mid term:"<<right<<setw(7)<<midterm; 
    cout<<"\n"; 
    cout<<"Final:"<<right<<setw(10)<<final; 
    cout<<"\n"; 
    cout<<".................................\n"; 
    cout<<"Total:"<<right<<setw(11)<<total; 
    cout<<"\n"; 
    system("PAUSE"); 
    return EXIT_SUCCESS; 
}

2. Given the following pseudo code, write a program that executes it.

a.     read x 
b.     read y
c.      compute p=x*y
d.     compute s=x+y
e.      total=s2+p*(s-x)*(p+y)
f.       print total

Solution:

 #include <cstdlib> 
#include <iostream> 
#include<iomanip> 
using namespace std; 
int main(int argc, char *argv[]) 
{ 
    float x; 
    float y; 
    float p; 
    float s; 
    float total; 
    cout<<"Enter x value:"; 
    cin>>x; 
    cout<<"\n"; 
    cout<<"Enter y value:"; 
    cin>>y; 
    cout<<"\n"; 
    p=x*y; 
    s=x+y; 
    total=s*s+p*(s-x)*(p+y); 
    cout<<"Total:"<<total; 
    cout<<"\n"; 
    system("PAUSE"); 
    return EXIT_SUCCESS; 
} 

No comments

Post a Comment