We have been working very hard since 2009 to facilitate in your learning Read More. We can't keep up without your support. Donate Now.

# www.vustudents.ning.com

 www.bit.ly/vucodes + Link For Assignments, GDBs & Online Quizzes Solution www.bit.ly/papersvu + Link For Past Papers, Solved MCQs, Short Notes & More

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
 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
 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: + http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

Views: 2729

### Replies to This Discussion

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.

solution        Attachments:

function define nahi karna tha kia assignment main

IS THIS SOLUTION IS CORRECT ?????

#include <iostream>
using namespace std;

struct Rectangle
{
float width,length,area;

float rectangleArea(float ,float)
{
area=width*length;
return area;
}
};
struct Trapezoid
{
float height,base1,base2,area;

float trapezoidArea(float ,float, float)
{
area=((base1+base2)/2)*height;
return area;
}
};

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

Nhn, function structure k andar nhn define krna,

Thanks Dear

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

Attachments:
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

welcome

#include
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;
do{
cout"\n\nEnter 1 to calculate the area of Rectangle"endl;
cout"Enter 2 to calculate the area of trapezoid\n\n";
cin>>choice1;
if(choice1==1){
cout"Enter the width of rectangle : ";
cin>>width;
cout"Enter the length of rectangle : ";
cin>>length;
rectArea = rectangleArea(width,length);
cout"The Area of Rectangle is : "rectAreaendl;
}
else if (choice1==2){
cout"Enter base1 of trapezoid : ";
cin>>base1;
cout"Enter base2 of trapezoid : ";
cin>>base2;
cout"Enter the height of trapezoid : ";
cin>>height;
trapeArea = trapezoidArea(base1,base2,height);
cout"The Area of trapezoid is : "trapeAreaendl;
}
else{
cout"Wrong Input";
}
cout"\nDo you want to do another calculation? : ";
cin>>choice2;
}while(choice2=='y' || choice2=='Y');
system("pause");
}

## HELP SUPPORT

This is a member-supported website. Your contribution is greatly appreciated!

.