Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

Assignment 2 of CS201 is continuity of assignment 1. You have to do the same task as you did in assignment 1 but this time you have to use structure variables. You have to write C++ program in which; 

• You are required to define 2 structures named as Rectangle and Trapezoid.
• Rectangle has 3 data members, width, length and area
• Trapezoid has 4 data members named as height, base1, base2 and area.
• Provide 2 options to the user as below:
 Enter 1 to calculate the area of Rectangle
 Enter 2 to calculate the area of a Trapezoid

• If the user enters 1, then 
 Object (variable) of Rectangle structure is created
 The program should ask the user to enter the width and length of the rectangle
 Assign input values to data members of Rectangle Structure
 Then show the result after calculation. Formula for calculating Area of rectangle is 
Area = width x Length.

• If the user enters 2, then 
 Object (variable) of Trapezoid structure is created
 The program should ask the user to enter the base1, base2, and height of the trapezoid
 Assign input values to data members of Trapezoid structure 
 Then shows the result after calculation. Formula for calculating Area of trapezoid is 
Area = 
• You must implement two different functions for calculating areas of rectangle and trapezoid.
• After taking the choice from the user in form of 1 or 2 and assigning entered values to respective structure data members, the relevant function should be called to calculate area.
• Function for calculating area should return a value that would be stored in data member of structure to store respective area.
• After storing area, it should be displayed on screen.
• After showing the output to the user, you need to ask the user if he/she wants to do another calculation. If the user presses y or Y, then the program should ask the user again to enter the choice of shape otherwise the program should be terminated.

Screenshot of the program execution is given below for both shapes:

Views: 2767

Replies to This Discussion

Please Discuss here about this assignment.Thanks

Our main purpose here discussion not just Solution

We are here with you hands in hands to facilitate your learning and do not appreciate the idea of copying or replicating solutions.



function define nahi karna tha kia assignment main


#include <iostream>
using namespace std;

struct Rectangle
float width,length,area;

float rectangleArea(float ,float)
return area;
struct Trapezoid
float height,base1,base2,area;

float trapezoidArea(float ,float, float)
return area;

int main()
char repeat;
int choice;
cout"\n\nPress 1 to calculate the area of Rectangle"endl;
cout"Press 2 to calculate the area of Trapezoid\n"endl;
cout"Enter your choice: ";
Rectangle object;
cout"\nEnter the width of rectangle: ";
cout"Enter the length of rectangle: ";
object.rectangleArea(object.width , object.length);
cout"The Area of Rectangle is: "object.area;
else if(choice==2)
Trapezoid object;
cout"\nEnter the base1 of trapezoid: ";
cout"Enter the base2 of trapezoid: ";
cout"Enter the height of trapezoid: ";
object.trapezoidArea(object.base1 , object.base2 , object.height);
cout"The Area of Trapezoid is: "object.area;
cout"Invalid Choice."endl;
cout"\n\nDo you want to do another calculation? (y/n): ";
while (repeat=='y'||repeat=='Y');

Nhn, function structure k andar nhn define krna,

Thanks Dear

CS201 assignment2 Correct solution, remove my comments add your's, change variable names

Kia structure or function dono use hn gay or structure ko jab initialize kartain hain tu dot (.) ka use hota hai ap nay tu nahi kia Amir bhai

Assignment men to ase he kaha gya he,

dot operator data member ko access krne k lye use hota he chah estructure ho ya class

thnk u so much


using namespace std;
double AreaofRectangle ();
double AreaofTrapezoid ();
double rectangleArea(double w,double l){
double rectArea;
rectArea = w* 1;
return rectArea;
double trapezoidArea(double b1,double b2,double h){
double trapeArea;
trapeArea + ((b1/b2)/2)*h;
return trapeArea;
int main(){
int choice1;
char choice2;
double width,length,rectArea,base1,base2,height,trapeArea;
cout"\n\nEnter 1 to calculate the area of Rectangle"endl;
cout"Enter 2 to calculate the area of trapezoid\n\n";
cout"Enter your choice : ";
cout"Enter the width of rectangle : ";
cout"Enter the length of rectangle : ";
rectArea = rectangleArea(width,length);
cout"The Area of Rectangle is : "rectAreaendl;
else if (choice1==2){
cout"Enter base1 of trapezoid : ";
cout"Enter base2 of trapezoid : ";
cout"Enter the height of trapezoid : ";
trapeArea = trapezoidArea(base1,base2,height);
cout"The Area of trapezoid is : "trapeAreaendl;
cout"Wrong Input";
cout"\nDo you want to do another calculation? : ";
}while(choice2=='y' || choice2=='Y');


© 2021   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service