0% found this document useful (0 votes)
7 views

Lab 5

Uploaded by

ahmadpsh305
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Lab 5

Uploaded by

ahmadpsh305
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

C:\Users\HP\source\repos\ConsoleApp3\Program.

cs 1
1 using ConsoleApp3;
2 using System;
3
4 class Shape
5 {
6
7 }
8 class realstate
9 {
10 public string str;
11 }
12
13 class Circle : Shape
14 {
15 private int radius;
16 public void Shape1()
17 {
18 Console.WriteLine("Enter the radius of the circle:");
19 radius = int.Parse(Console.ReadLine());
20 }
21 public double CalculateArea()
22 {
23 return 3.1416 * radius * radius;
24 }
25 public override string ToString()
26 {
27 return $"Circle with radius {radius}";
28 }
29 }
30
31 class Rectangle : Shape
32 {
33 private int height;
34 private int width;
35 public void Shape2()
36 {
37 Console.WriteLine("Enter the height and width of the rectangle:");
38 height = int.Parse(Console.ReadLine());
39 width = int.Parse(Console.ReadLine());
40 }
41 public int CalculateArea()
42 {
43 return height * width;
44 }
45 public override string ToString()
46 {
47 return $"Rectangle with height {height} and width {width}";
48 }
49 }
C:\Users\HP\source\repos\ConsoleApp3\Program.cs 2
50
51 class Cube : Shape
52 {
53 private int height;
54 private int width;
55 private int depth;
56
57 public void Shape3()
58 {
59 Console.WriteLine("Enter the height, width, and depth of the
cube:");
60 height = int.Parse(Console.ReadLine());
61 width = int.Parse(Console.ReadLine());
62 depth = int.Parse(Console.ReadLine());
63 }
64
65 public int CalculateArea()
66 {
67 return 2*((height*width)+(width*depth)+(height*depth));
68 }
69
70 public override string ToString()
71 {
72 return $"Cube with height {height}, width {width}, and depth
{depth}";
73 }
74 }
75
76 class Program
77 {
78 static void Main(string[] args)
79 {
80 Shape[] shapes = new Shape[100];
81 realstate[] Real = new realstate[100];
82 int circleCount = 0;
83 int rectangleCount = 0;
84 int cubeCount = 0;
85 double totalCircleArea = 0;
86 int totalRectangleArea = 0;
87 int totalCubeArea = 0;
88 int shapeCount = 0;
89 int hostelcount = 0, apartmentcount = 0, officecount = 0,
realcount = 0;
90 int harea = 0, aarea = 0, oarea = 0;
91
92 while (true)
93 {
94 Console.WriteLine("1. Geometric");
95 Console.WriteLine("2. Realstate");
C:\Users\HP\source\repos\ConsoleApp3\Program.cs 3
96 Console.WriteLine("3. Exit");
97 int x = int.Parse(Console.ReadLine());
98 if (x == 1)
99 {
100
101 while (true)
102 {
103 Console.WriteLine("1. Add circle");
104 Console.WriteLine("2. Add rectangle");
105 Console.WriteLine("3. Add cube");
106 Console.WriteLine("4. Item list");
107 Console.WriteLine("5. Statistics");
108 Console.WriteLine("6. Back");
109 Console.WriteLine("7. Exit");
110
111 int n = int.Parse(Console.ReadLine());
112
113 if (n == 1)
114 {
115 Circle circle = new Circle();
116 circle.Shape1();
117 shapes[shapeCount] = circle;
118 totalCircleArea += circle.CalculateArea();
119 circleCount++;
120 shapeCount++;
121 }
122 else if (n == 2)
123 {
124 Rectangle rectangle = new Rectangle();
125 rectangle.Shape2();
126 shapes[shapeCount] = rectangle;
127 totalRectangleArea += rectangle.CalculateArea();
128 rectangleCount++;
129 shapeCount++;
130 }
131 else if (n == 3)
132 {
133 Cube cube = new Cube();
134 cube.Shape3();
135 shapes[shapeCount] = cube;
136 totalCubeArea += cube.CalculateArea();
137 cubeCount++;
138 shapeCount++;
139 }
140 else if (n == 4)
141 {
142 Console.WriteLine("Item List:");
143 for (int i = 0; i < shapeCount; i++)
144 {
C:\Users\HP\source\repos\ConsoleApp3\Program.cs 4
145 Console.WriteLine($"{i + 1}. {shapes[i]}");
146
147 }
148 }
149 else if (n == 5)
150 {
151 Console.WriteLine($"Number of circles:
{circleCount}");
152 Console.WriteLine($"Number of rectangles:
{rectangleCount}");
153 Console.WriteLine($"Number of cubes:
{cubeCount}");
154 Console.WriteLine($"Total area of circles:
{totalCircleArea:F3}");
155 Double p = (totalCircleArea * 100) /
(totalCircleArea + totalRectangleArea + totalCubeArea);
156 Console.WriteLine($"Percentage of circle: {p}");
157 Console.WriteLine($"Total area of rectangles:
{totalRectangleArea}");
158 p = (totalRectangleArea * 100) / (totalCircleArea
+ totalRectangleArea + totalCubeArea);
159 Console.WriteLine($"Percentage of rectangle:
{p}");
160 Console.WriteLine($"Total area of cubes:
{totalCubeArea}");
161 p = (totalCubeArea * 100) / (totalCircleArea +
totalRectangleArea + totalCubeArea);
162 Console.WriteLine($"Percentage of cube: {p}");
163 Console.WriteLine($"Total area: {totalCircleArea +
totalRectangleArea + totalCubeArea}");
164 }
165 else if (n == 6)
166 {
167 break;
168 }
169 else if (n == 7)
170 {
171 Environment.Exit(0);
172 }
173 }
174 }
175 else if (x == 2)
176 {
177
178 while (true)
179 {
180 Console.WriteLine("1. Apartment");
181 Console.WriteLine("2. Hostel");
182 Console.WriteLine("3. Office");
C:\Users\HP\source\repos\ConsoleApp3\Program.cs 5
183 Console.WriteLine("4. Itemlist");
184 Console.WriteLine("5. Statistics");
185 Console.WriteLine("6. Back");
186 Console.WriteLine("7. Exit");
187 int y;
188 y = int.Parse(Console.ReadLine());
189
190 if (y == 1)
191 {
192
193 Apartment apartment = new Apartment();
194 apartment.apartment();
195 Real[realcount] = apartment;
196 aarea += apartment.apartmentarea();
197 hostelcount++;
198 realcount++;
199
200
201 }
202 else if (y == 2)
203 {
204 Hostel hostel = new Hostel();
205 hostel.hostel();
206 Real[realcount] = hostel;
207 harea += hostel.hostelarea();
208 officecount++;
209 realcount++;
210 }
211 else if (y == 3)
212 {
213 Office office = new Office();
214 office.office();
215 Real[realcount] = office;
216 oarea += office.officearea();
217 officecount++;
218 realcount++;
219 }
220 else if (y == 4)
221 {
222 Console.WriteLine("Item List:");
223 for (int i = 0; i < realcount; i++)
224 {
225 Console.WriteLine($"{i + 1}. {Real[i]}");
226
227 }
228 }
229 else if (y == 5)
230 {
231 // Console.WriteLine($"Number of circles:
C:\Users\HP\source\repos\ConsoleApp3\Program.cs 6
{circleCount}");
232 // Console.WriteLine($"Number of rectangles:
{rectangleCount}");
233 ///Console.WriteLine($"Number of cubes:
{cubeCount}");
234 Console.WriteLine($"Total area of Apartment:
{aarea}");
235 Double p = (aarea * 100) / (aarea + harea +
oarea);
236 Console.WriteLine($"Percentage of Apartment:
{p}");
237 Console.WriteLine($"Total area of Hostel:
{harea}");
238 p = (harea * 100) / (aarea + harea + oarea);
239 Console.WriteLine($"Percentage of Hostel: {p}");
240 Console.WriteLine($"Total area of Offic:
{oarea}");
241 p = (oarea * 100) / (aarea + harea + oarea);
242 Console.WriteLine($"Percentage of office: {p}");
243 Console.WriteLine($"Total area: {aarea + harea +
oarea}");
244 }
245 else if (y == 6)
246 {
247 break;
248 }
249 else if (y == 7)
250 {
251 Environment.Exit(0);
252 }
253
254
255 }
256 }
257
258 else if (x == 3)
259 { Environment.Exit(0); }
260
261 }
262
263
264 }
265
266
267 }
268

You might also like