Question

This lab is to give you more experience with CH Making Decisions and Looping Please do the following Review Questions 1. Usin

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)

/*******************Com.cpp****************/

#include<iostream>
using namespace std;

int main(){
  
   float commisionRate = 0,salesAmount;
  
   cout<<"Enter sales amount";
   cin>>salesAmount;
   while(salesAmount<0){
      
       cout<<"Enter valid amount";
       cin>>salesAmount;
   }
  
   if(salesAmount<=10000){
      
       commisionRate = 10;
   }
   else if(salesAmount>10000&&salesAmount<=15000){
      
       commisionRate = 15;
   }
   else{
      
       commisionRate = 20;
   }
  
   cout<<"Your commission rate is "<<commisionRate;
  
   return 0;
}

/*************output*********************/

Enter sales amount14000
Your commission rate is 15
--------------------------------

D:AChegg-workspace\com.exe Enter sales amount14000 Your commission rate is 15

2)

/**********************precision.cpp*********************/

#include<iostream>
#include <iomanip>
using namespace std;

int main(){
  
   double number = 678.34598654;
   int choice;
   cout<<"Enter choice between 1 and 4";
   cin>>choice;
   switch(choice){
      
       case 1:
           cout<<fixed<<showpoint<<setprecision(2);
           break;
       case 2:
               cout<<fixed<<showpoint<<setprecision(4);
           break;
       case 3:
               cout<<fixed<<showpoint<<setprecision(4);
           break;
       case 4:
               cout<<fixed<<showpoint<<setprecision(6);
           break;
       default :
               cout<<fixed<<showpoint<<setprecision(8);
           break;
   }
  
   cout<<number;
   return 0;
}

/*****************output****************/

Enter choice between 1 and 43
678.3460
--------------------------------

DAChegg-workspace\precision.exe Enter choice between 1 and 43 678.3460 Process exited after 1.701 seconds with return value P

3)

/***************************num.cpp**************/

#include<iostream>
using namespace std;

int main(){
  
   double number;
   cout<<"Enter number: ";
   cin>>number;
  
   if(number>=0&&number<=100){
      
       cout<<"Number is valid";
   }
   else{
      
       cout<<"The number is invalid";
   }
   return 0;
}

/**************output**********/

Enter number: 101
The number is invalid
--------------------------------

DAChegg-workspace\num.exe Enter number: 101 The number is invalid Process exited after 1.627 seconds with return value e Pres

4)

/*********************que4.cpp**************/

#include<iostream>
using namespace std;

int main(){
  
   cout<<"Print sum of even number"<<endl;
   int number,sum = 0;
   for(number=2;number<=100;number++){
      
       if(number%2==0){
          
           sum+=number;
       }
   }
  
   cout<<"Sum of even number between 2 and 100 is "<<sum<<endl;
  
   cout<<"\nSum of square"<<endl;
   sum = 0;
   for(number=1;number<=100;number++){
  
       sum+=number*number;      
   }
  
   cout<<"sum of squres: "<<sum<<endl;
  
   int a,b,i;
   sum = 0;
   cout<<"sum of odd numbers between a and b"<<endl;
   cout<<"Enter a : ";
   cin>>a;
   cout<<"Enter b: ";
   cin>>b;
   for(i=a;i<=b;i++){
      
       if(i%2==1){
          
           sum+=i;
       }
   }
  
   cout<<"Sum of all odd number between "<<a<<" and "<<b<<" is: "<<sum;
   return 0;
}

/*********output*************/

Print sum of even number
Sum of even number between 2 and 100 is 2550

Sum of square
sum of squres: 338350
sum of odd numbers between a and b
Enter a : 1
Enter b: 10
Sum of all odd number between 1 and 10 is: 25
--------------------------------

DAChegg-workspace\sum.exe Print sum of even number Sum of even number between 2 and 100 is 2550 Sum of square sum of squres:

Q5)

a) loop will execute 1 to 10 with increment of 1

b) loop will execute 0 to 9 with increment of 1

c) loop will execute 10 to 1 with decrement of 1

c) loop will execute -10 to 10 ,increment of 1

d) loop will execute -10 to 10 with increment of 2 every time.

Please let me know if you have any doubt or modify the answer, Thanks :)

Add a comment
Know the answer?
Add Answer to:
This lab is to give you more experience with CH Making Decisions and Looping Please do...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ problem where should I do overflow part? in this code do not write a new...

    C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...

  • Can someone please tell me why the calculation for earnings is not coming through at the...

    Can someone please tell me why the calculation for earnings is not coming through at the end of the program? Thank you. //This program should tell us about streaming services #include <iostream> #include <iomanip> #include <string> using namespace std; int main() {    int choice, streams;    double earnings;    string song;    string artist;    string streamingService;       const int Tidal = 0.01250;    const int Amazon = 0.00402;    const int Apple_Music = 0.00735;    const int...

  • QUESTION 7 Which of the following is a valid C++ assignment statement? (assume each letter is...

    QUESTION 7 Which of the following is a valid C++ assignment statement? (assume each letter is a different variable) A.y=b-c B.y +z = x C.x = a bi D.x = -(y*z): Ex = (x + (y z): QUESTION 8 Which of the following is a valid variable name according to C++ naming rules? A 2ndName B.%Last_Name C@Month D#55 Eyear03 QUESTION 9 Which library must be included to enable keyboard input? A kbdin B. cstdlib C input Diostream E lomanip QUESTION...

  • How to turn this file into a main.cpp, a header which contains the function declaration, and...

    How to turn this file into a main.cpp, a header which contains the function declaration, and a implementation fiel containing the function definition ? #include<iostream> #include<string> #include<iomanip> using namespace std; #define NUM 1 #define MULT 4 void getPi(int iter); int main() {    int it;    cout << "Enter the number of iterations needed to find PI: ";    cin >> it;    while (it < 1) {        cout << "Error!!! Iteration input should be positive." << endl;...

  • I need help finding the several errors and several loop errors for I get the final...

    I need help finding the several errors and several loop errors for I get the final output. C++ cLion #include <iostream> using namespace std; int main() { cout << "Welcome to Loop World" << endl; cout << endl; cout << "******************" << endl; cout << "Section I" << endl; cout << "******************" << endl; int sum; // Accumulates the total int i; // Used as loop control variable int numIter; // The number of times to iterate cout << "Enter...

  • C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you...

    C++ Redo PROG8, a previous program using functions and/or arrays. Complete as many levels as you can. Level 1: (20 points) Write FUNCTIONS for each of the following: a) Validate #students, #scores. b) Compute letter grade based on average. c) Display student letter grade. d) Display course average. Level 2: (15 points) Use ARRAYS for each of the following. e) Read a student's scores into array. f) Calculate the student's average based on scores in array. g) Display the student's...

  • // This program displays a menu and asks the user to make a 2 // selection....

    // This program displays a menu and asks the user to make a 2 // selection. An if/else if statement determines which item 3 // the user has chosen. 4 #include <iostream> 5 #include <iomanip> 6 using namespace std; 7 8 int main() 9 { 10 int choice; // To hold a menu choice 11 int months; // To hold the number of months 12 double charges; // To hold the monthly charges 13 14 // Constants for membership rates...

  • CIS 22B Lab 3 Itty Bitty Airfreight (IBA) Topics: Friend functions Copy constructor ----------------------------------------------------------------------------------------------------------------------------------------- Lab 3.1...

    CIS 22B Lab 3 Itty Bitty Airfreight (IBA) Topics: Friend functions Copy constructor ----------------------------------------------------------------------------------------------------------------------------------------- Lab 3.1 Utilizing Lab 2.2 code Create your objects in the stack (not on the heap). Add a friend function, kilotopound, which will convert kilograms to pounds. Change your weight mutator to ask whether weight is input in kilograms or pounds. If it is kilograms, call the friend function kilotopound to convert it to pounds and return pounds.There are 2.2 pounds in one kilogram. Create an...

  • Find and fix the errors in this C++ code: * This program illustrates a variety of...

    Find and fix the errors in this C++ code: * This program illustrates a variety of common loop errors. * Fix the errors in each section. */ #include <iostream> using namespace std; int main() { cout << "Welcome to Loop World" << endl; // SECTION I: update comment below on how you fixed this section's code, and tests run // FIX = // TESTS: cout << endl; cout << "******************" << endl; cout << "Section I" << endl; cout <<...

  • Please pay special attention to the question asked. Code written must work when replacing it for...

    Please pay special attention to the question asked. Code written must work when replacing it for "//write your code here" in the image below. Must be in C++ I only need the code to replace "//write your code here" with. You don't need to resend the given code. The given code in text format for your convenience: #include <iostream> #include <iomanip> using namespace std; //rectangle class class Rectangle { public: double areaOfRectangle(double l, double w) { if (l > 0...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT