﻿ C++ exercises and solutions: arithmetic compound operators

C++ exercises and solutions: arithmetic compound operators

C++ arithmetic and compound operators

1.Write a C++ program to produce the output as shown below:

Results:

x value y   value   expressions   results
10            | 5         | x=y+3       | x=8
10            | 5         | x=y-2        | x=3
10            | 5         | x=y*5        | x=25
10            | 5         | x=x/y         | x=2
10            | 5         | x=x%y       |  x=0

Solution:
#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
int x;
int y;
x=10;
y=5;
cout<<"Result:\n";
cout<<"x value\t"<<"y value\t"<<"Expressions\t"<<"Result\n";
cout<<x<<" |\t"<<y<<" |\t"<<"x=y+3\t"<<"\t|"<<"x="<<y+3<<"\n";
cout<<x<<" |\t"<<y<<" |\t"<<"x=y-2\t"<<"\t|"<<"x="<<y-2<<"\n";
cout<<x<<" |\t"<<y<<" |\t"<<"x=y*5\t"<<"\t|"<<"x="<<y*5<<"\n";
cout<<x<<" |\t"<<y<<" |\t"<<"x=x/y\t"<<"\t|"<<"x="<<(float)(x/y)<<"\n";
cout<<x<<" |\t"<<y<<" |\t"<<"x=x%y\t"<<"\t|"<<"x="<<x%y<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
}

2. Write a program to produce the output as shown below:

Results:

x value y value expressions results
10       | 5         | x+=y      | x=15
10       | 5         | x-=y-2    | x=7
10       | 5         | x*=y*5   | x=250
10       | 5         | x/=x/y     | x=5
10       | 5         | x%=y     | x=0

Solution:
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int x;
int y;
x=10;
y=5;
cout<<"Result:\n";
cout<<"x value\t"<<"y value\t"<<"Expressions\t"<<"Result\n";

cout<<x<<" |\t"<<y<<" |\t"<<"x+=y\t"<<"\t|"<<"x="<<x+y<<"\n";
cout<<x<<" |\t"<<y<<" |\t"<<"x=y-2\t"<<"\t|"<<"x="<<x-(y-2)<<"\n";
cout<<x<<" |\t"<<y<<" |\t"<<"x=y*5\t"<<"\t|"<<"x="<<x*y*5<<"\n";
cout<<x<<" |\t"<<y<<" |\t"<<"x=x/y\t"<<"\t|"<<"x="<<(float)x/(x/y)<<"\n";
cout<<x<<" |\t"<<y<<" |\t"<<"x=x%y\t"<<"\t|"<<"x="<<x%y<<"\n";

system("PAUSE");
return EXIT_SUCCESS;
} Usman1.write a program that input property in rupees ,number of sons,number of daughter and input Y if the widow is alive and calculate the share of each son and calculate the share of each daugter and widow solve in Dev C++ 2017-11-06 raviDevelop a class to represent one digit counter. The class must have data member to represent counter. The class should have following function a. Function to set the value of the counter b. Function to display value of the counter c. Function to increment the counter d. Function to decrement the counter2017-11-05 Hamish hameed #include main() { char asterisk='*'; for(int count=1;count<=8;count++){ for(int i=8;i>=count;i--){ cout< int main() { char c = { '*' }; for (int i = 9; i > 0; i--) { for (int j = i; j > 0; j--) { std::cout << c; } std::cout << std::endl; } }2017-03-16 desai ramesh******** ******* ****** ***** **** *** ** * this is output show this loop.2017-03-07 Jefferson@ebessien #include #include using namespace std; int main() { string Asterisk = "*"; for (int count = 1; count <= 8; count++) { for (int i = 8; i >= count; i--){ cout << Asterisk; }cout << endl; } }2017-01-18 سیناممنون از مثال ها/thanks for example :)2016-04-30 hackernever say thankyou 2016-04-28 ebessienUsing for loop, write a write a C++ program be using two For loops to produce the output shown below ******** ******* ****** ***** **** *** ** * 2016-04-06 KophyoThanks!2016-02-22 nkishor thanku 2015-08-03