Given a problem and program, fill up the blank spaces in the program in order to make the program work correctly. --------------------------------------------------------------- Health Center hospital has a registration form for the patients to register their details. Exceptions should be handled when the patient enters his/her details, because the users may enter invalid details into the form(For example age should have only positive values). Implement this concept by using Exception handling in c++. The class named Register with the following constructor and methods. Constructor Description Register(string name,int age,string gender,int height,int weight) Set the values passed as parameters. void display() This method displays patient's name,age,gender,height,weight. Input and Output Format : Refer sample input and output for formatting specifications. All text in bold corresponds to input and the rest corresponds to output. Sample Input and Output: Enter your name Nivya Enter your age -21 Exception: Age should be positive Enter your age again 21 Enter your gender Female Enter your height(in centimeters) 156 Enter your weight(in kilograms) -48 Exception: Weight should be positive Enter your weight(in kilograms) again 48 Name : Nivya Age : 21 Gender : Female Height : 156 cm Weight : 48 kg ----------- PLACE TO FILLUP IN BELOW PROGRAM AT LINE NUMBER 43 , 60 , 75 ----------------------------------------- 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 class Register { 7 public: 8 string name,gender; 9 int age,weight,height; 10 public: 11 Register() 12 { 13 } 14 Register(string name,int age,string gender,int height,int weight) 15 { 16 this->name = name; 17 this->age = age; 18 this->gender = gender; 19 this->height = height; 20 this->weight = weight; 21 } 22 public: 23 virtual void display() 24 { 25 cout <<"Name : "<>name; 39 try 40 { 41 cout <<"Enter your age"<>age; 43 if(___________) 44 { 45 throw "Exception: Age should be positive"; 46 } 47 } 48 catch(const char* msg) 49 { 50 cerr << msg << endl; 51 cout <<"Enter your age again"<>age; 53 } 54 cout <<"Enter your gender"<>gender; 56 try 57 { 58 cout <<"Enter your height(in centimeters)"<>height; 60 if( __________ ) 61 { 62 throw "Exception: Height should be positive"; 63 } 64 } 65 catch(const char* msg) 66 { 67 cerr << msg << endl; 68 cout <<"Enter your height(in centimeters) again"<>height; 70 } 71 try 72 { 73 cout <<"Enter your weight(in kilograms)"<>weight; 75 if( __________________) 76 { 77 throw "Exception: Weight should be positive"; 78 } 79 } 80 catch(const char* msg) 81 { 82 cerr << msg << endl; 83 cout <<"Enter your weight(in kilograms) again"<>weight; 85 } 86 Register r(name,age,gender,height,weight); 87 r.display(); 88 return 0; 89 }
Given a problem and program, fill up the blank spaces in the program in order to make the program work correctly.
Health Center hospital has a registration form for the patients to register their details. Exceptions should be handled when the patient enters his/her details, because the users may enter invalid details into the form(For example age should have only positive values). Implement this concept by using Exception handling in c++.
The class named Register with the following constructor and methods.
Constructor | Description |
Register(string name,int age,string gender,int height,int weight) | Set the values passed as parameters. |
void display() | This method displays patient's name,age,gender,height,weight. |
Input and Output Format :
Refer sample input and output for formatting specifications.
All text in bold corresponds to input and the rest corresponds to output.
Sample Input and Output:
Enter your name
Nivya
Enter your age
-21
Exception: Age should be positive
Enter your age again
21
Enter your gender
Female
Enter your height(in centimeters)
156
Enter your weight(in kilograms)
-48
Exception: Weight should be positive
Enter your weight(in kilograms) again
48
Name : Nivya
Age : 21
Gender : Female
Height : 156 cm
Weight : 48 kg
----------- PLACE TO FILLUP IN BELOW PROGRAM AT LINE NUMBER 43 , 60 , 75 -----------------------------------------
1 #include<iostream>
|
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 5 images