943,621 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 811
  • C++ RSS
Apr 11th, 2008
0

bloodDonor class

Expand Post »
Hi
this is my question , and I have some error in my code ,and I cant correct them ,and I am asking if you could help me ?
this is the question :
Create a class called BloodDonor that maintains information about blood donors in a blood bank having the following data members:
1. IdNumber, // long int
2. name, //Name of donor
3. bloodGroup//String
4. home_Phone//String
5. mobile_Phone//String
6. address // struct Address that holds int house number, int road number, int block
number, string city, and string country
It will also have the following member functions:
1. Constructor function with default values IdNumber = 0, name = "", bloodGroup = "",
home_Phone="", mobile_Phone="", address={0,0,0,"",""} An overloaded constructor that takes the same parameters of the constructor in except
Address for the address
2. Set and get functions for all data members. The setBloodgroup function should check
the validity of the blood group before assigning it to bloodGroup by calling the
function Is_BloodBroup_Valid described below.
3. Overloaded functions for setAddress one that takes an Address as parameter and the
other one takes int,int,int,string [], and string[] for address
4. Is_BloodBroup_Valid // takes a string as parameter and return true if it is a valid
group and false if not. The only possible blood groups are A+, A-, B+, B-, 0+, 0-,
AB+, AB-.
5. InputDetails// asks the user to enter all the details of a donor and then assign the
values to the data members by calling the appropriate set functions.
6. printDetails // Print the details (IdNumber,name, bloodGroup, home phone, mobile
phone, and address) of the donor
8. Destructor function.
PART A
Write the class BloodDonor including the code of the member functions.
PART B
Write a main function which includes the following:
1. Creates an instance (object) named donor1 of type BloodDonor with id=567JJ9, name is
Ahmed, blood group is B+, home phone="17123456", mobile phone="39999999",
address={ l,l,l,"Manama","Bahrain"}-
2. Write a statement to change the mobile phone to "39888888".
3. Write a statement to print the mobile phone.
4. Write a statement to print the details of donor.
5. Create another object named donor2 of type BloodDonor.
6. Ask the user to enter the details of the donor2 by calling InputDetails function
7. Print the details of donor2.

this is my code
C++ Syntax (Toggle Plain Text)
  1. #include<iostream>
  2. #include<string>
  3. using namespace std ;
  4. struct Address {
  5. int house ,road ,block;
  6. string city,country;
  7. };
  8. class BloodDonor {
  9. private:
  10. long IdNumber;
  11. string name ;
  12. string bloodGroup;
  13. string home_Phone;
  14. string mobile_Phone;
  15. Address add;
  16. public:
  17. BloodDonor(int id=0,string nm=" ",string bldGrp=" ",string hmPHn=" ",string mblPhn ,Address add={0,0,0," "," "});
  18. BloodDonor(int ,string ,string,string );
  19. void getBloodgroup ( long &id, string &nm, String &bldGrp, String &hmPHn,String &mblPhn );
  20. void setBloodgroup ( long IdNumber, string name, String bloodGroup, String home_Phone,String mobile_Phone);
  21. bool Is_BloodGroup_Valid (string bloodGroup);
  22. void setAddress(int h ,int r, int b, string c,string count );
  23. void setAddress(Address a);
  24. void InputDetails();
  25. void printDetails ();
  26. ~ BloodDonor();
  27. };
  28. BloodDonor bldDnr;
  29. void BloodDonor::setAddress(int h ,int r, int b, string c,string count ){
  30. add.house=h;
  31. add.road=r;
  32. add.city=c;
  33. add.country=count;
  34. }
  35. void BloodDonor::setAddress(Address a){
  36. add.house=a.house;
  37. add.road=a.road;
  38. add.city=a.city;
  39. add.country=a.country;
  40. }
  41.  
  42.  
  43. BloodDonor::~ BloodDonor(){
  44. cout<<" terminate objects";
  45. }
  46.  
  47. void BloodDonor::InputDetails(){
  48.  
  49. cout<<"Enter the donor details as follow "<<endl;
  50. cout<<"adress";
  51. cout<<"house";
  52. cin>>add.house;
  53. cout<<"road";
  54. cin>>add.road;
  55. cout<<"block";
  56. cin>>add.block;
  57. cout<<"city";
  58. cin>>add.city;
  59. cout<<"country";
  60. cin>>add.country;
  61. bldDnr.setAddress( add.house,add.road,add.block,add.city,add.country);
  62.  
  63.  
  64. }
  65.  
  66. bool BloodDonor::Is_BloodGroup_Valid (string &bloodGroup){
  67.  
  68. enum bloodType {A+,A-,B+,B-,AB+,AB-,O+,O-};
  69. switch (bloodGroup){
  70. case "A+":
  71. bloodGroup="A+";
  72. break;
  73. case "A-":
  74. bloodGroup="A-";
  75. break;
  76. case "B+":
  77. bloodGroup="B+";
  78. break;
  79. case "B-":
  80. bloodGroup="B-";
  81. break;
  82. case AB+:
  83. bloodGroup="AB+";
  84. break;
  85. case "AB-":
  86. bloodGroup="AB-";
  87. break;
  88. case "O+":
  89. bloodGroup="O+";
  90. break;
  91. case "O-":
  92. bloodGroup="O-";
  93. break;
  94. return true;
  95. default :
  96. return false;
  97.  
  98. }
  99. void BloodDonor::setBloodgroup( long IdNumber, string name, String bloodGroup, String home_Phone,String mobile_Phone){
  100.  
  101. id=IdNumber;
  102. nm=name;
  103. bldGrp=bloodGroop;
  104. hmPHn=home_Phone;
  105. mblPhn=mobile_Phone;
  106. }
  107. void BloodDonor::getBloodgroup(long &id, string &nm, String &bldGrp, String &hmPHn,String &mblPhn){
  108. IdNumber=id;
  109. name=nm;
  110. bloodGroop=bldGrp;
  111. home_Phone=hmPHn;
  112. mobile_Phone=mblPhn;
  113. bldDnr.Is_BloodGroup_Valid(bldGrp
  114. }
  115. void BloodDonor::printDetails(){
  116. bldDnr.setBloodgroup()
  117. cout<<"Id"<<IdNumber<<endl;
  118. cout<<"Blood Groop"<<bloodGroop<<endl;
  119. cout<<"home_Phone"<<home_Phone<<endl;
  120. cout<<"mobile_Phone"<<mobile_Phone<<endl;
  121. }
  122.  
  123. int main(){
  124. BloodDonor donor1 (567889,Ahmed,B+,"17123456","39999999",111,Manama,Bahrain);
  125. BloodDonor donor2;
  126. BloodDonor donor1 (567889,Ahmed,B+,"17123456","39888888",111,Manama,Bahrain);
  127. donor1.printDetails();
  128. donor2.InputDetails();
  129. donor2.printDetails();
  130.  
  131.  
  132. return 0;
  133. }
  134.  
  135.  
  136.  
  137.  
  138. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bis student is offline Offline
16 posts
since Dec 2007
Apr 11th, 2008
-1

Re: bloodDonor class

>>and I have some error in my code ,and I cant correct them
I just got new glasses the other day but I'm still having problems seeing the errors you get on your monitor. So would you post them here to make them easier to read ?
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Apr 11th, 2008
0

Re: bloodDonor class

You have many many errors in your code. Are there any errors in particular that you're having trouble understanding?


you don't need the line: BloodDonor bldDnr; or any reference to bldDnr

your enum bloodType tries to use invalid characters as variable/enumeration names. Try using allowable names.

setting the default address struct value should can be done like this:
BloodDonor(int id=0,string nm=" ",string bldGrp=" ",string hmPHn=" ",string mblPhn ,Address add=(struct Address){0,0,0," "," "});

Note the casting.

oooh, the list goes on. Use your compiler generated errors to pinpoint where you're going wrong and fix the code 1 line at a time. Eventually there will be no errors.
Reputation Points: 85
Solved Threads: 45
Posting Whiz in Training
dougy83 is offline Offline
275 posts
since Jun 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: accessing 2d array as 1d array
Next Thread in C++ Forum Timeline: XML Parsing





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC