111 views

Uploaded by Adonis Brown

1st programming assignement Summer Semester 2007

save

You are on page 1of 4

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 <iostream.h>

#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<<name<<", please choose one of the selections below:"<<endl

<<"------------------"<<endl;

cout<<"R = Rectangle |"<<endl<<"P = Parallellogram|"<<endl<<"T = Trapezoid

|"<<endl;

cout<<"------------------"<<endl;

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

}

- Area planning.pdf.pdfUploaded byK Ouertani
- formal lesson plan 4Uploaded byapi-383424069
- Math 103Uploaded byRoger Wang
- FIELD WORK NO. 4 DETERMINING THE AREA OF A POLYGONAL FIELD USING ONLY THE TAPE.pdfUploaded byJawahir Gomez
- CAT 2008 SolutionsUploaded bysanjay singh
- 10 mathsUploaded byDhinesh Babu Rajendran
- 32324-PythonBeginnersWorkbookforSecondarySchools1Uploaded byphysicscarp
- nullUploaded byapi-26274024
- Calculating Volume of Three Dimensional ShapesUploaded bymattsabu
- 2018 State Countdown RoundUploaded byYougui Liao
- class_10_2Uploaded byEmil Lewin Lukose
- A Camera is Accidentally Knocked Off a Ledge of a CliffUploaded byVeeraragavan Subramaniam
- 193078437-Formula-for-Press-Tool-Design.pdfUploaded byRoshini Despicable
- Areas of CirclesUploaded bysumit67
- GE QuizUploaded byRhea Celzo
- Std07 Maths EM 2Uploaded bykodatic
- Lektion1 Lehrer ProduktionUploaded byValeria J Iglesias C
- DAO SYLLABUS 2018 IN APUploaded bySWETHA LATHA
- Chapter 8 Applications of Perimeter , Area and VolumeUploaded byAaron Kirk
- Nix the TricksUploaded byJohn Doe
- Scaling FundamentalsUploaded byMark Prochaska
- Intermediate 2 Unit 1 and 2 RevisionUploaded byknoxmaths
- 2009 Dhs h2 PromoUploaded byNBzzz
- ed603final justinemUploaded byapi-302258576
- 0580_s17_qp_22Uploaded byyuke kristina

- Advanced GRE Math Questions - Version 3Uploaded byDillon Valadez
- 1. Integral IndefinidaUploaded byRenzo Terrones Murga
- Tabla de IntegralesUploaded bytomas gonzalez
- TOPIC 11 PerimeterAreaUploaded byZuraini Arshad
- chezy.pdfUploaded byAnonymous J1Plmv8
- Stresses in Soil 161208Uploaded byTuan Jalai
- TCS1Uploaded byapi-3832274
- towerpaperUploaded byapi-312570323
- 3478_Chapter_6Uploaded byMd Ruhul Amin
- 100411 41 Fase 4 TrabajocolaborativoUploaded byAnonymous vipWk59e
- 1 La AntiderivadaUploaded byJorge Victor Moreno Gomez
- Teacher’s Resource Book 2Uploaded byNauman Iqbal
- Carpentry Math Assessment ReviewUploaded byctinker10
- Algebra i Formula ChartUploaded byJesse Garrard
- Surface Area All ShapeUploaded byBasheer Ahmed
- contenido del curso evaluacin y bibliografaUploaded byapi-126851571
- 307875087-Chapter-7-Wind-Loads-Egyptian-Load-Code.pdfUploaded byNeeraja
- Curso de Logica e ProgramacaoUploaded byRichardlazer Sandro
- SilverCalcReviewUploaded byJhayr Pascua
- Chapter13.pdfUploaded byPedraza Velandia Jhon
- unidades_de_superficieUploaded byandespc
- Quantity SurveyorUploaded byFaizan Ahmad
- Sujet Eliminatoires Categorie D 2016Uploaded byRamarolahy Dadan'i Elia
- Integration 1Uploaded byEdward Anastassacos
- MathsUploaded byAsh
- Hydraulic Arm ProjectUploaded byGovind Rajput
- Sample Tiered Math ProblemsUploaded byFirman S
- Spherical SegmentUploaded bychadlow
- planimeterUploaded bydukenmarga
- 9Uploaded byjitender8