Program 1

  • Uploaded by: Adonis Brown
  • 0
  • 0
  • July 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Program 1 as PDF for free.

More details

  • Words: 608
  • Pages: 4
CSCI 229 C++ for Engineers Summer 2006 Due Date: Tuesday, June 19, 2007; no later than 10:00 p.m.

Problem Description: Students at a local middle school that you have been tutoring are having some difficulty with basic area formulas that they learn in math class. You decided to write a simple computer program that will help them with a few of these concepts. Program Directions: Write a C++ program that uses the information found in the formula section to calculate the area of a rectangle, parallelogram, or trapezoid. The program must do the following: • Ask the user to input his/her first name • Ask the user to choose the shape of which to calculate the area o Program must take both upper and lower characters • Ask the user to input the lengths and/or the height of shape • Calculate the area of the shape • Display to the screen the area of the shape Formulas

rectangle = ab

parallelogram = bh

trapezoid = h/2 (b1 + b2)

Program Output The program should display the following: • The name of the user • The area of the shape

Program Calculations Failure to include the formulas in the program will result in a deduction of points on the assignment. Program Header Information • Name • Program number • Collaboration statement • The answers to the following question: o What is the purpose of the program? o What is the input? (Is there any?) o What is the output? Failure to include this information as comments at the beginning of your program will result in a deduction of point. Sample Run Below is a sample run. DO NOT include additional input or output streams in your program.

This program received 100/100 points from Dr. Cynthia Lester. /* Adonis Brown Program #1 I worked on the assignment by myself and received no additional assistance. Questions: 1. The purpose of this program is to find the area of a certain shape (using user entered integers), then print it to the screen. 2. The inputs are the sides (and heights of certain shapes), as well as the user's name. 3. The outputs are the area of the figure whose sides (and heights)were input, as well as the user's name when asking for input.*/ #include <string> #include #include <stdlib.h> int main() { char shape; string name; double rs1 = 0, rs2 = 0, pb = 0, ph = 0, tb1 = 0, tb2 = 0, th = 0; cout <<"Please enter your name:"<<endl; cin>>name; cout<<endl<>shape; if (shape == 'R'||shape == 'r') {

cout<<"Please enter the lengths of the two sides of the rectangle: "; cin>>rs1>>rs2; if (rs1 <= 0 || rs2 <= 0) cout<<"The lengths can not be negative."<<endl; else cout<<"The area of your rectangle is "<<(rs1*rs2)<<"."<<endl; } else if (shape == 'P'||shape == 'p') { cout<<"Please enter the length of the base of your parallellogram: "; cin>>pb; cout<<"Please enter the height of your parallellogram: "; cin>>ph; if (pb <= 0 || ph <= 0) cout<<"The lengths can not be negative."<<endl; else cout<<"The area of your parallellogram is "<<(pb*ph)<<"."<<endl; } else if (shape == 'T'||shape == 't') { cout<<"Please enter the first base of your trapezoid: "; cin>>tb1; cout<<"And now the second base: "; cin>>tb2; cout<<"Finally, enter the height of your trapezoid: "; cin>>th; if (tb1 <= 0 || tb2 <= 0 || th <=0) cout<<"The lengths can not be negative."<<endl; else cout<<"The area of your trapezoid is "<<(th/2*(tb1 + tb2))<<"."<<endl; } else cout<<shape<<" is not a valid entry."<<endl; system("PAUSE"); return 0; }

Related Documents

Program 1
April 2020 12
Program 1
November 2019 12
Program 1
April 2020 4
Program 1
April 2020 6
Program 1
May 2020 13
Program 1
July 2019 29

More Documents from "Adonis Brown"

Program 2
August 2019 30
Program 1
July 2019 29
October 2019 48
October 2019 21
Karevane Islam
October 2019 23
October 2019 30