University of Bahrain
College of Information Technology
Department of Computer Science

ITCS102: C++ Programming Assignment #5

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
  7. 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:
  8. 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"}-
  9. Write a statement to change the mobile phone to "39888888".
  10. Write a statement to print the mobile phone.
  11. Write a statement to print the details of donor.
  12. Create another object named donor2 of type BloodDonor.
  13. Ask the user to enter the details of the donor2 by calling InputDetails function
  14. Print the details of donor2.

this an assigment that i try to solvit but i couldent , please help me to know the corect solve
this is my try

include<iostream>
include<string>

using namespace std;

struct Address{
    int house_number,road_number,block_number;
    string city, country;
}add;

bool Is_BloodBroup_Valid(string BG)
{
  if(BG=="A+"||BG== "A-"||BG== "B+"||BG== "B-"||BG== "0+"||BG== "0-"||BG=="AB+"||BG=="AB")
      return true;
  else
      return false;

}

void InputDetails()
{
    long id;
    string name,BG,HP,MP;
    Address add;

    cout<<"Enter The Donor ID: ";
    cin>>id;
    cout<<"nEnter The Donor Name: ";
    cin>>name;
    cout<<"nEnter The Donor Blood Group: ";
    cin>>BG;
    cout<<"nEnter The Donor Home Phone: ";
    cin>>HP;
    cout<<"nEnter The Donor Mobile Phone: ";
    cin>>MP;
    cout<<"nEnter The Donor Address: nHouse Num.: ";
    cin>>add.house_number;
    cout<<"nRoad Num.: ";
    cin>>add.road_number;
    cout<<"nBlock Num.: ";
    cin>>add.block_number;
    cout<<"nCity Country";
    cin>>add.city>>add.country;
}

    //Constructor functions 

 BloodDonor::BloodDonor(long id ,string name,string BG,string HP,string MP,int HN,int RN,int BN,string city,string country)
{
    setAll( id,name,BG,HP,MP,add);
}

BloodDonor::BloodDonor(long id ,string name,string BG,string HP,string MP,Address add)
{
    setAll();
} //Constructor functions

//Set functions

void BloodDonor::setAll (long id ,string name,string BG,string HP,string MP,Address add )
{
    setIdNumber(id);
    setName(name);
    setBloodGroup(BG);
    setHome_phone(HP);
    setMobile_phone(MP);
    setAddress(add);
}

void BloodDonor::setIdNumber(long id)
{
    IdNumber=id;
}

void BloodDonor::setName(string name)
{
    nameOfDonor=name;
}

void BloodDonor::setBloodGroup(string BG)
{
    if(Is_BloodBroup_Valid(BG))
        bloodGroup=BG;
}

void BloodDonor::setHome_phone(string HP)
{
    home_phone=HP;
}

void BloodDonor::setMobile_phone(string MP)
{
    mobile_phone=MB;
}

void BloodDonor::setAddress(Address add)
{
    address=add;
}

void BloodDonor::setAddress(int house,int road,int block,string city,string country)
{
    address.house_number=house;
    address.road_number=road;
    address.block_number=block;
    address.city=city;
    address.country=country;
}//Set functions

//Get functions

void BloodDonor::getAll(long &,string &,string &,string &,string &,Address &)
{
    getIdNumber();
    getName();
    getBloodGroup();
    getHome_phone();
    getMobile_phone();
    getAddress();
}

void BloodDonor::getIdNumber()
{
    id=IdNumber;
}

void BloodDonor::getName()
{
    name=nameOfDonor;
}

void BloodDonor::getBloodGroup()
{
        BG=bloodGroup;
}

void BloodDonor::getHome_phone()
{
    HP=home_phone;
}

void BloodDonor::getMobile_phone()
{
    MP=mobile_phone;
}

void BloodDonor::getAddress()
{
    add=address;
}

void BloodDonor::getAddress(int& house,int& road,int &block,string& city,string& country)
{
    house=address.house_number;
    road=address.road_number;
    block=address.block_number;
    city=address.city;
    country=address.country;
}//Get functions

void BloodDonor::print(long id,string name,string BG,string HP,string MP,Address add)
{
    cout<<"ID number: "<<id<<"nName of Donor: "<<name<<"nBlood group: "<<BG
        <<"nHome phone: "<<HP<<"nMobile phone: "<<MP<<endl;

    cout<<"nAddress:"<<"nHouse num. "<<add.house_number<<"nRoad num. "<<add.road_number
        <<"nBlock num. "<<add.block_number<<"nCity: "<<add.city<<"nCountry: "<<add.country<<endl;
}

class BloodDonor{


    long IdNumber;
    string nameOfDoner,bloodGroup,home_phone,mobile_phone;
    Address add;

    public:

    //Constructor functions 

    BloodDonor(long=0 ,string ="",string ="",string ="",string ="",int =0,int =0,int =0,string ="",string ="");
    BloodDonor(long  ,string ,string ,string ,string ,Address add);
    //Set functions
    void setAll(long,string,string,string,string,Address);

    void setIdNumber(long);
    void setName(string);
    void setBloodGroup(string);
    void setHome_phone(string);
    void setMobile_phone(string);

    void setAddress(Address);
    void setAddress(int,int,int,string,string);

    //Get functions


    void getAll(long&,string&,string&,string&,string&,Address&);

    void getIdNumber();
    void getName();
    void getBloodGroup();
    void getHome_phone();
    void getMobile_phone();

    void getAddress();
    void getAddress(int&,int&,int&,string&,string&);


    void print(long,string,string,string,string,Address);

    //Destructor function
    ~BloodDoner();  
};

int main()
{


  BloodDonor donor1;
  donor1.setAll(567JJ9,Ahmed,B+,17123456,39999999,111,Manama,Bahrain);
  donor1.setMobile_phone(39888888);
  donor1.print(39888888);
  donor1.print();
  BloodDonor donor2;
  donor2.InputDetails();
  donor2.print();


    return 0;
}
BloodDonor(long=0 ,string ="",string ="",string ="",string ="",int =0,int =0,int =0,string ="",string ="");

don't think you can set default types in c++

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.