PROGRAM DESCRIPTION The purpose of this programming project

PROGRAM DESCRIPTION: The purpose of this programming project is to write a C++ program that uses loops and For reference, refer to the following diagram of an isosceles trapezoid with its formula to functions to print out an isosceles trapezoid and calculate its area compure its area: As with all homework programs in this course, your program\'s output initialy dsplay the department and course number, your name, your EUID, and your e mail address You will prompt the user to enter an odd integer between 1 and 21, indlusively. to use as the top base, br. of the trapezoid. You will validale the users input by creaing a programmer-defined function to ensure that the integer is an odd nteger in the range 1 to 21, inclusively. The integer entered by the user should be passed as a parameter to this function at a minimum (read: more parameters may be passed as needed) If the integer is not valid, you wil continually te- prompt the user to enter the integer again until the user enters a valid integer The rebum type of this function should be a Boolean data type and you are to use this Boolean result in determining whether or not the user input is valid Once the user has entered a valid integer for the top base of the trapezoid, you will then prompt the user to enter an odd integer between 3 and 23, inclusively, lo use as the bottom base, ba, of the trapezoid with the condition that the bottom base, ba, is greater than the top base, bi. To valdate the botom base, ba, you will use (and modfy as needed) the programmer-defined function used to validate the top base, b, being sure to enforce the new range and the inequality hat ba is greater than b. Similarly, if the integer is not valid, you will continualy r rompt the user to enter the integer again unti the user enters a vaid integer You will prompt the user for and read in a printable character that will be used to draw the trapezoid. You may assume that the user enters a printable character You will draw the trapezoid using a programmer-defined function that accepts both integers (for each trapezoid base, b and ba) and the printable character

Solution

#include <iostream>
using namespace std;

int main(){

   int x,y;
   char character;
   cout << \"Department name, Course name, name, EUID, mail address.\" << endl;
   while(1){
       cout << \"Enter an odd integer in the range 1-21 inclusive as top base: \";
       cin >> x;
       if( x >= 1 && x <= 21 && x%2 == 1 ){ //got the input
           break;
       }
       cout << \"Invalid integer. Try Again.\" << endl;
   }
   while(1){
       cout << \"Enter an odd integer in the range 3-23 inclusive as bottom base(> \";
       cout << x << \"): \";
       cin >> y;
       if( y > x && y <= 23 && y%2 == 1 ){ //got the input
           break;
       }
       cout << \"Invalid integer. Try Again.\" << endl;
   }
   cout << \"Enter a printable character to draw a trapezoid: \";
   cin >> character;

   //Draw trapezoid
   int drawHM = x;
   while( drawHM <= y ){
       for(int i =0; i < y-(drawHM-x)/2; i++){ cout << \" \"; }
       for(int i =0; i < drawHM; i++){ cout << character; }
       cout << endl;
       drawHM += 2;
   }
   //calculate area
   int area = ((y+x)/2)*( (y-x)/2 + 1 );
   cout << \"Area of the above trapezoid is: \" << area << endl;

   return 0;
}

 PROGRAM DESCRIPTION: The purpose of this programming project is to write a C++ program that uses loops and For reference, refer to the following diagram of an
 PROGRAM DESCRIPTION: The purpose of this programming project is to write a C++ program that uses loops and For reference, refer to the following diagram of an

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site