C++ exercises and solutions: C++ operators (con)


C++ operators (con)

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


Comments

Sumon comment

 Sumon

The solution of this problem is .....


#include <iostream>
using namespace std;
int main()
{
int q1,q2,q3,mid_term,final_term,final,total;

cout << "Enter your score of first quiz : "<< endl;
cin >> q1;

cout << "Enter your score of seacond quiz :" << endl;
cin >> q2;
cout << "Enter your score of third quiz : "<< endl;
cin >> q3;
cout << "Enter your score of the mid term marks :"<< endl;
cin >> mid_term;
cout << "Enter your score of the final marks : "<< endl;
cin>> final;

cout << "Quiz Total : " << q1+q2+q3 <<endl;
cout << "Mid term : " << mid_term <<endl;
cout << "Final : " << final << endl;
cout << "Total : " << q1+q2+q3+mid_term+final<< endl;

return 0;


2017-05-28
ashutosh.raja94@gmail.com comment

 ashutosh.raja94@gmail.com

solution to the first problem

#include <iostream>

using namespace std;
int main()
{
int q1,q2,q3,mid ;
cout<<"**********quiz***************"<<endl;
cout<<"enter the score of quiz one ="<<endl;
cin>>q1;
cout<<"enter the score of quiz two ="<<endl;
cin>>q2;
cout<<"enter the score of quiz three ="<<endl;
cin>>q3;
cout<<"**********mid term ***************"<<endl;
cout<<"enter the score of midterm ="<<endl;
cin>>mid;
cout<<"**********total***************"<<endl;
cout<<"total of quiz score "<<q1+q2+q3<<endl;
cout<<" mid term total "<<mid<<endl;
cout<<"grand total "<<q1+q2+q3+mid<<endl;
return 0;
}


2017-03-17
Aqeel  comment

 Aqeel

Its a pre-processor directive and also a library that is used to use the setw(n) function...


2015-09-18
Bassam  comment

 Bassam

i believe it is a library that contains functions as setw() that is used in the code for excercise 1.


2015-06-21
Humza comment

 Humza

What is #include<iomanip>


2015-06-04



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.