I am trying to write a code (object oriented programming) based on the requirements below however my bool kept returning a true whereas it should be false. Hope you guys can advise me on what went wrong with my code.
REQUIREMENTS
Member(string = "xxx", bool = false, string = "addr") Constructor with default values setMember(string, bool, string): void Set the values of data members to the respective pass-in values setPremium(bool): void Set the value of data member, premium to the pass-in value getPremium():bool Returns the value of data member, premium setMember(string, bool, string): void Set the values of data members to the respective pass-in values displayMember():void Uses cout to display the data members MY CODE
#include <iostream> #include <string> using namespace std; class Member { private: string name; bool premium; string address; public: Member(string = "xxx", bool = false, string = "addr"); void setMember(string, bool, string); void setPremium(bool); bool getPremium(); int index; void DisplayMember(); }; Member::Member(string name, bool premium, string address) { this-> name = name; this-> premium = premium; this-> address = address; } void Member::setMember(string name, bool premium, string address) { this-> name = name; this-> premium = premium; this-> address = address; } void Member::setPremium(bool) { int i; bool premium; i = 0; while (i != 4) { i = i + 1; } if (premium >= 4) { index = i; premium = true; } else premium = false; } bool Member::getPremium() { return premium; } void Member::DisplayMember() { cout<<"Name : "<<name<<endl; cout<<"Premium : "<<boolalpha<<premium<<endl; cout<<"Address : "<<address<<endl; } int main() { Member detail1("Martin ", "2 Tampines Avenue"); detail1.DisplayMember(); cin.ignore(); cin.ignore(); }