-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFigureArea.cpp
More file actions
53 lines (40 loc) · 1.01 KB
/
FigureArea.cpp
File metadata and controls
53 lines (40 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string>
#define CH 50
using namespace std;
struct term{
string c;
double value;
double area;
double result;
};
int main(){
cout.setf(ios::fixed);
cout.precision(2);
ifstream infile;
infile.open("hw2.txt");
string s1 = "triangle";
string s2 = "rectangle";
string s3 = "circle";
term A[CH];
for (int i = 0; i<7; i++){
infile >> A[i].c;
if (s1.compare(A[i].c)==0){
infile >>A[i].value >> A[i].area;
A[i].result = (A[i].value*A[i].area)*0.5;
}
else if(s2.compare(A[i].c)==0){
infile >> A[i].value >>A[i].area;
A[i].result = A[i].value * A[i].area;
}
else if(s3.compare(A[i].c)==0){
infile >> A[i].value;
A[i].result = A[i].value *A[i].value;
}
}
for(int i =0; i<7; i++){
cout<<A[i].c<<" "<<A[i].value<<" "<<A[i].area<<" "<<A[i].result<<endl;
}
}