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.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
 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:


+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

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

+ Click Here to Search (Looking For something at vustudents.ning.com?)

+ Click Here To Join (Our facebook study Group)


Views: 2729

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.

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;
cout"Enter your choice: ";
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";
cout"Enter your choice : ";
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");
}

RSS

Looking For Something? Search Here

Latest Activity

Zoey D replied to +!!! Alan Walker!!!'s discussion Dosri shaadi....Mani bro soch lo:-P
14 minutes ago
Zoey D replied to Zoey D's discussion * Aks paani men*...!!!!
19 minutes ago
Zoey D replied to Zoey D's discussion Udaas q ho..????
22 minutes ago
Zoey D replied to Zoey D's discussion Udaas q ho..????
23 minutes ago
Zoey D replied to Zoey D's discussion Behtar Hei.....!!!
24 minutes ago
Zoey D liked Zoey D's discussion *¨*• ♡ Kia bht zarori hei.. ♡ •*¨*??
29 minutes ago
Zoey D liked Zoey D's discussion Hath khali hen tery shehr sei jaty jaty ... !!
29 minutes ago
Zoey D liked Zoey D's discussion * Aks paani men*...!!!!
29 minutes ago

HELP SUPPORT

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

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

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

.