-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMainProgramme.c
260 lines (214 loc) · 8.56 KB
/
MainProgramme.c
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// 11-Nov 2021 Kannav Created this
// 12-Nov 2021 Kannav Modified the files and added the functions
// 13-Nov 2021 Kannav finalised the programme
// 15-Nov 2021 Kannav and Bhavjot Tested and documented the code
// 16-Nov 2021 Samay reworked On the code
#define _CRT_SECURE_NO_WARNINGS
#define InterestRate 0.05 //Defining the interest rate
#include <stdio.h>
#include <string.h>
#include "MainHeaderFile.h"// include the main header file
int main(void) {
//Creating all the variables required to take input from the file
char address[255];
int rooms;
int bathrooms;
double purchasePrice;
double monthlyRent;
double monthlyUtilities;
double monthlyCondoFees;
double monthlyPropertyTax;
struct RealEstate property;
struct RealEstate *p=&property;
double MEarnings=0;
double ROI=0;
double Currentv=0;
double Capitalg=0;
int n =1;
int SumP=0;
FILE *fp = fopen("Apartments.txt", "r");// Opening the appartments file to read text
// assigning the data to the appartments structure
for (int i = 0; i < NUM_PROPERTY; ++i) {
fscanf(fp, "%[^\n]s", address);
fscanf(fp, "%d", &rooms);
fscanf(fp, "%d", &bathrooms);
fscanf(fp, "%lf", &purchasePrice);
fscanf(fp, "%lf", &monthlyRent);
fscanf(fp, "%lf", &monthlyCondoFees);
strcpy(p->appartments[i].address,address);
p->appartments[i].Nrooms=rooms;
p->appartments[i].Nbathrooms=bathrooms;
p->appartments[i].PurchasePrice=purchasePrice;
p->appartments[i].MonthlyRent=monthlyRent;
p->appartments[i].MonthlyCFees=monthlyCondoFees;
p->appartments[i].MonthlyEarnings=MonthlyEarningsAppartment(p->appartments[i].MonthlyRent,p->appartments[i].MonthlyCFees);
p->appartments[i].CurrentV=CurrentValue(p->appartments[i].MonthlyEarnings);
p->appartments[i].CapitalG=CapitalGains(p->appartments[i].CurrentV,p->appartments[i].PurchasePrice);
SumP=SumP+p->appartments[i].PurchasePrice;
while (fgetc(fp) != '\n');//clearing the file buffer before the next fscanf()
}
// Calculating Everything for the appartment section
MEarnings=TotalMonthlyEarningsAppart(&property,n);
ROI=ReturnOnInvestment(MEarnings,SumP);
Currentv=TotalCvalueAppart(&property,n);
Capitalg=TotalCapitalGainsAppart(&property,n);
// priinting out the values for the appartment
printf("The following are financial stats for Brookfield Asset Management, 11 Yonge Street.\n\n");
printf("For the apartments, the monthly earnings are $%.2lf, the roi is %.2lf%% the total value is $%.2lf and the capital gains are $%.2lf\n\n",MEarnings,ROI,Currentv,Capitalg);
fclose(fp);
SumP=0;
n=2;
fp = fopen("Townhouses.txt", "r");
for (int i = 0; i < NUM_PROPERTY; ++i) {
fscanf(fp, "%[^\n]s", address);
fscanf(fp, "%d", &rooms);
fscanf(fp, "%d", &bathrooms);
fscanf(fp, "%lf", &purchasePrice);
fscanf(fp, "%lf", &monthlyRent);
fscanf(fp, "%lf", &monthlyUtilities);
fscanf(fp, "%lf", &monthlyCondoFees);
fscanf(fp, "%lf", &monthlyPropertyTax);
strcpy(p->townhouses[i].address,address);
p->townhouses[i].Nrooms=rooms;
p->townhouses[i].Nbathrooms=bathrooms;
p->townhouses[i].Pprice=purchasePrice;
p->townhouses[i].MonthlyRent=monthlyRent;
p->townhouses[i].MonthlyCFees=monthlyCondoFees;
p->townhouses[i].MonthlyUtilities=monthlyUtilities;
p->townhouses[i].MonthlyPropertyTax=monthlyPropertyTax;
p->townhouses[i].MonthlyEarnings=MonthlyEarningsTownHouses(p->townhouses[i].MonthlyRent,p->townhouses[i].MonthlyPropertyTax,p->townhouses[i].MonthlyUtilities, p->townhouses[i].MonthlyCFees);
p->townhouses[i].CurrentV=CurrentValue(p->townhouses[i].MonthlyEarnings);
p->townhouses[i].CapitalG=CapitalGains(p->townhouses[i].CurrentV,p->townhouses[i].Pprice);
SumP=SumP+p->townhouses[i].Pprice;
while (fgetc(fp) != '\n');//clear the file buffer before the next fscanf()
}
MEarnings=TotalMonthlyEarningsAppart(&property,n);
ROI=ReturnOnInvestment(MEarnings,SumP);
Currentv=TotalCvalueAppart(&property,n);
Capitalg=TotalCapitalGainsAppart(&property,n);
fclose(fp);
printf("For the townhouses, the monthly earnings are $%.2lf, the roi is %.2lf%% the total value is $%.2lf and the capital gains are $%.2lf\n\n",MEarnings,ROI,Currentv,Capitalg);
//Retrieve data for semi-detached houses
n=3;
SumP=0;
fp = fopen("SemiDetachedHouses.txt", "r");
for (int i = 0; i < NUM_PROPERTY; ++i) {
fscanf(fp, "%[^\n]s", address);
fscanf(fp, "%d", &rooms);
fscanf(fp, "%d", &bathrooms);
fscanf(fp, "%lf", &purchasePrice);
fscanf(fp, "%lf", &monthlyRent);
fscanf(fp, "%lf", &monthlyUtilities);
fscanf(fp, "%lf", &monthlyPropertyTax);
strcpy(p->houses[i].address,address);
p->houses[i].Nrooms=rooms;
p->houses[i].Nbathrooms=bathrooms;
p->houses[i].Pprice=purchasePrice;
p->houses[i].MonthlyRent=monthlyRent;
p->houses[i].MonthlyUtilities=monthlyUtilities;
p->houses[i].MonthlyPropertyTax=monthlyPropertyTax;
p->houses[i].MonthlyEarnings=MonthlyEarningsHouses(p->houses[i].MonthlyRent, p->houses[i].MonthlyUtilities,p->houses[i].MonthlyPropertyTax);
p->houses[i].CurrentV=CurrentValue(p->houses[i].MonthlyEarnings);
p->houses[i].CapitalG=CapitalGains(p->houses[i].CurrentV,p->houses[i].Pprice);
SumP=SumP+p->houses[i].Pprice;
while (fgetc(fp) != '\n');//clear the file buffer before the next fscanf()
}
MEarnings=TotalMonthlyEarningsAppart(&property,n);
ROI=ReturnOnInvestment(MEarnings,SumP);
Currentv=TotalCvalueAppart(&property,n);
Capitalg=TotalCapitalGainsAppart(&property,n);
printf("For the semi detached houses, the monthly earnings are $%.2lf, the roi is %.2lf%% the total value is $%.2lf and the capital gains are $%.2lf\n\n",MEarnings,ROI,Currentv,Capitalg);
fclose(fp);
return 0;
}
double MonthlyEarningsHouses(double MonthlyRent,double MonthlyUtilities ,double MonthlyPropertyTax){
double monthlyEarnings;
monthlyEarnings = MonthlyRent-MonthlyUtilities-MonthlyPropertyTax;
return monthlyEarnings;
}
// calculate the Return on investment for a single property
double ReturnOnInvestment(double MonthlyEarnings,double Pprice){
double rinvestment;
rinvestment=(100*12*MonthlyEarnings)/Pprice;
return rinvestment;
}
// calculate the current value of a single property
double CurrentValue(double MonthlyEarnings){
double cValue;
cValue=12*MonthlyEarnings/InterestRate;
return cValue;
}
// calculate the capitalgains for a single property
double CapitalGains(double CurrentValue, double Pprice){
double CapitalG;
CapitalG=CurrentValue-Pprice;
return CapitalG;
}
// calculate the total monthly earnings for a specific property
double TotalMonthlyEarningsAppart(struct RealEstate *property,int n){
double SumM=0;
if(n==1){
for(int i =0;i<NUM_PROPERTY;i++){
SumM=SumM+property->appartments[i].MonthlyEarnings;
}
}
else if(n==2){
for(int i =0;i<NUM_PROPERTY;i++){
SumM=SumM+property->townhouses[i].MonthlyEarnings;
}
}
else{
for(int i =0;i<NUM_PROPERTY;i++){
SumM=SumM+property->houses[i].MonthlyEarnings;
}
}
return SumM;
}
double TotalCvalueAppart(struct RealEstate *property,int n){
double SumM=0;
if(n==1){
for(int i =0;i<NUM_PROPERTY;i++){
SumM=SumM+property->appartments[i].CurrentV;
}
}
else if(n==2){
for(int i =0;i<NUM_PROPERTY;i++){
SumM=SumM+property->townhouses[i].CurrentV;
}
}
else{
for(int i =0;i<NUM_PROPERTY;i++){
SumM=SumM+property->houses[i].CurrentV;
}
}
return SumM;
}
double TotalCapitalGainsAppart(struct RealEstate *property,int n){
double SumM=0;
if(n==1){
for(int i =0;i<NUM_PROPERTY;i++){
SumM=SumM+property->appartments[i].CapitalG;
}
}
else if(n==2){
for(int i =0;i<NUM_PROPERTY;i++){
SumM=SumM+property->townhouses[i].CapitalG;
}
}
else{
for(int i =0;i<NUM_PROPERTY;i++){
SumM=SumM+property->houses[i].CapitalG;
}
}
return SumM;
}
double MonthlyEarningsTownHouses(double MonthlyRent,double MonthlyUtilities ,double MonthlyPropertyTax,double MonthlyCondoFees){
double monthlyEarnings;
monthlyEarnings = MonthlyRent-MonthlyUtilities-MonthlyPropertyTax-MonthlyCondoFees;
return monthlyEarnings;
}
double MonthlyEarningsAppartment(double MonthlyRent,double MonthlyPropertyTax){
double monthlyEarnings;
monthlyEarnings = MonthlyRent-MonthlyPropertyTax;
return monthlyEarnings;
}