Student ID: Marks AWaiu Submission Date: 11 April 2018 Total Marks: 30 ASSIGNMEN
ID: 3704596 • Letter: S
Question
Student ID: Marks AWaiu Submission Date: 11 April 2018 Total Marks: 30 ASSIGNMENT NO. 2 [CLO 2 10 Marks, CLO 3 20 Marks] HOW TO SUBMIT? I. Submit these pages with the assignment. 2 The salved assignment submitted MUST be stapled with ONE staple an left upper corner and use A4 size paper. d rite programs using DEV C IDE.compile run and take the screen shot of the output and submit. 4. 5. The submitted programs MUST be handwritten. Use the goad programming practices: this will have marks STUDENTS MAY BE ASKED TO EXPLAIN THE PROGRAMS-NO LATE ASSIGNMENTS OBEJCTIVE Use control structures in C programs. (CLO 2) Demonstrate the use of functions in C programs.(CLO 3) REFERENCE MATERIAL Textbook Lecture Notes Supplementary Notes Internet ONo. CLO 02/0 Marks 10/2 Write three functions (I) rectangleArea (2) circleArea, and (3) triangleArea to compute and return the area of a rectangle, circle, and triangle, respectively Use these functions in a program in which program will compute and print the area of (a) rectangle if user will enter 'R' or 'r (b) circle if user will enter C' or 'c (c) triangle if user will enter T' or 't' The program will discontinue (stop) if user will enter 'E' or'e'.Explanation / Answer
#include<iostream.h>
//using namespace std;
float rectangleArea()
{
float len=0;
float brth=0;
float area=0;
cout<<"Enter Length and breadth of Rectagle";
cin>>len>>brth;
area=len*brth;
return area;
}
float traingleArea()
{
float base=0;
float height=0;
float area=0;
cout<<"Enter base and height of Traingle";
cin>>base>>height;
area=base*height*.5;
return area;
}
float circleArea()
{
float radius=0;
float area=0;
cout<<"Enter radius of circle";
cin>>radius;
area=3.14*radius*radius;
return area;
}
void main()
{
char choice;
float area=0;
cout<<"Enter a character to Calculate Area of Rectangle,Cirle and Traingle"<<endl;
cout<<"Press R or r to calculate rectangleArea"<<endl;
cout<<"Press C or c to calculate CircleArea"<<endl;
cout<<"Press T or t to calculate TraingleArea"<<endl;
while(1)
{
cin>>choice;
if(choice=='R'||choice=='r')
{
area=rectangleArea();
cout<<"Area of Rectagle"<<area;
}
else if(choice=='T'||choice=='t')
{
area=traingleArea();
cout<<"Area of Traingle"<<area;
}
else if(choice=='C'||choice=='c')
{
area=circleArea();
cout<<"Area of Circle"<<area;
}
else if(choice=='E'||choice=='e')
{
break;
}
}
}