-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphysicalData.cpp
More file actions
282 lines (246 loc) · 8.25 KB
/
physicalData.cpp
File metadata and controls
282 lines (246 loc) · 8.25 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
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#include "physicalData.h"
#include<iostream>
#include<string>
#include<fstream>
#include <cctype>//toupper
#include"Exception.h"
#include<limits>//for exception
using namespace std;
PhysicalData::PhysicalData() {
weight = 0.0f;
length = 0.0f;
headCircumference = 0.0f;
temperature = 0.0f;
age=0;
momAge=0;
gender='N';
}
PhysicalData::PhysicalData(float weight, float length, float headCircumference, float temperature,int age,int momAge,char gen) {
this->weight = weight;
this->length = length;
this->headCircumference = headCircumference;
this->temperature = temperature;
this->age=age;
this->momAge=momAge;
this->gender=gen;
}
PhysicalData::PhysicalData(const PhysicalData& other) {
weight = other.weight;
length = other.length;
headCircumference = other.headCircumference;
temperature = other.temperature;
age=other.age;
momAge=other.momAge;
gender=other.gender;
}
PhysicalData::~PhysicalData() {
}
double PhysicalData::getWeight() const {
return weight;
}
void PhysicalData::setWeight(float weight) {
this->weight = weight;
}
char PhysicalData::getGender() const {
return gender;
}
void PhysicalData::setGender(char gen) {
this->gender = gen;
}
double PhysicalData::getLength() const {
return length;
}
void PhysicalData::setLength(float length) {
this->length = length;
}
double PhysicalData::getHeadCircumference() const {
return headCircumference;
}
void PhysicalData::setHeadCircumference(float headCircumference) {
this->headCircumference = headCircumference;
}
double PhysicalData::getTemperature() const {
return temperature;
}
void PhysicalData::setTemperature(float temperature) {
this->temperature = temperature;
}
int PhysicalData::getAge() const{
return age;
}
void PhysicalData::setAge(int age)
{
this->age=age;
}
int PhysicalData::getMomAge() const{
return momAge;
}
void PhysicalData::setMomAge(int momAge)
{
this->momAge=momAge;
}
istream& operator>>(istream& in, PhysicalData& physic) {
cout << "Enter Weight of the baby: (in kgs)";
in >> physic.weight;
cout << "Enter Length of the baby: (in cm)";
in >> physic.length;
cout << "Enter Head Circumference: (in cm)";
in >> physic.headCircumference;
cout << "Enter Temperature of the Baby(in celsius): ";
in >> physic.temperature;
cout<<"Enter Age of the baby: ";
in>>physic.age;
cout<<"Enter Gender of the baby: (M or F)";
in>>physic.gender;
cout<<"Enter Age of the Mother: ";
in>>physic.momAge;
return in;
}
ostream& operator<<(ostream& output, const PhysicalData& physic) {
output << "Weight: " << physic.weight << " kg\n";
output << "Length: " << physic.length << " cm\n";
output << "Head Circumference: " << physic.headCircumference << " cm\n";
output << "Temperature: " << physic.temperature << " celsius\n";
output<<"Age of the Baby: "<<physic.age<<endl;
output<<"Gender of the Baby: "<<physic.gender<<endl;
output<<"Age of the Mother: "<<physic.momAge<<endl;
return output;
}
void PhysicalData::inputDetails() {
bool validInput = false;
while (!validInput) {
try {
cout << "Enter Weight of the baby:(in kgs)====>approx range according to age(1 month to 10 years) (2.5kg to 23.5kg) ";
cin >> weight;
if (cin.fail()|| weight < 2.5 || weight > 23.5) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
throw InvalidInputException();
}
validInput = true;
} catch (InvalidInputException& e) {
cerr << e.what() << endl;
}
}
setWeight(weight);
validInput = false;
while (!validInput) {
try {
cout << "Enter Length of the baby:(in cm)====>approx range according to age(1 month to 10 years) (47cm to 124.4cm): ";
cin >> length;
if (cin.fail()|| length < 47.0 || length > 124.4) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
throw InvalidInputException();
}
validInput = true;
} catch (InvalidInputException& e) {
cerr << e.what() << endl;
}
}
setLength(length);
validInput = false;
while (!validInput) {
try {
cout << "Enter Head Circumference: (in cm)===>approx range(34 to 67 cm)";
cin >> headCircumference;
if (cin.fail()|| headCircumference < 34.0 || headCircumference > 67.0) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
throw InvalidInputException();
}
validInput = true;
} catch (InvalidInputException& e) {
cerr << e.what() << endl;
}
}
setHeadCircumference(headCircumference);
validInput = false;
while (!validInput) {
try {
cout << "Enter Temperature of the Baby(in Celsius):===>approx range(35.9C to 37.3C) ";
cin >> temperature;
if (cin.fail()|| temperature < 35.9 || temperature > 37.3) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
throw InvalidInputException();
}
validInput = true;
} catch (InvalidInputException& e) {
cerr << e.what() << endl;
}
}
setTemperature(temperature);
validInput = false;
while (!validInput) {
try {
cout<<"Enter Age of the baby:(in months) ";
cin>>age;
if (cin.fail()||age<0||age>120) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
throw InvalidInputException();
}
validInput = true;
} catch (InvalidInputException& e) {
cerr << e.what() << endl;
}
}
setAge(age);
validInput = false;
while (!validInput) {
try {
cout<<"Enter Gender of the baby: (M or F)";
cin>>gender;
gender = toupper(gender);
if (cin.fail()||(gender!='M' && gender!='F')) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
throw InvalidInputException();
}
validInput = true;
} catch (InvalidInputException& e) {
cerr << e.what() << endl;
}
}
setGender(gender);
validInput = false;
while (!validInput) {
try {
cout<<"Enter Age of the Mother: ";
cin>>momAge;
if (cin.fail()||momAge>70||momAge<0) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
throw InvalidInputException();
}
validInput = true;
} catch (InvalidInputException& e) {
cerr << e.what() << endl;
}
}
setMomAge(momAge);
}
void PhysicalData::saveToFile(ofstream& outFile) {
outFile.open("physicaltest.bin", ofstream::out | ofstream::binary | ofstream::trunc);
if (!outFile.is_open()) {
cout << "Error: Unable to open file for writing" << endl;
return;
}
outFile << "\nPhysical Test Data" << endl;
outFile << "Weight of the baby: " << weight <<"kg"<< endl;
outFile << "Length of the baby: " << length <<"cm"<< endl;
outFile << "Head circumference of the baby: " << headCircumference <<"cm"<< endl;
outFile << "Age of Baby: " << age << endl;
outFile << "Gender of Baby: " << gender << endl;
outFile << "Age of Mother: " << momAge << endl;
outFile.close();
}
void PhysicalData::display() const {
cout << "Weight: " << weight << " pounds\n";
cout << "Length: " << length << " inches\n";
cout << "Head Circumference: " << headCircumference << " inches\n";
cout << "Temperature: " << temperature << " Fahrenheit\n";
cout << "Age of Baby: " << age << endl;
cout << "Age of Mother: " << momAge << endl;
}