Question: I have all the code below. I need to add new choice options, If user enters 4 then the Banana field of all the KongCrew
I have all the code below. I need to add new choice options, If user enters 4 then the Banana field of all the KongCrew is updated like this: Banana += Jump * 5 after calculating that print and list the KongCrew who has more than 15 bananas
then if the user enters 5 print and list only the dixie family members
#include
using namespace std;
class DK_OOP { public: /*Data member of DK_OOP class*/ string name, sit, walk, swing, leap, family; int jump, banana, year; /*Constructors of DK_OOP class*/ DK_OOP() {
} DK_OOP(string name, string sit, string walk, string swing, string leap, int jump, int banana, int year, string family) { this -> name = name; this -> sit = sit; this -> walk = walk; this -> swing = swing; this -> leap = leap; this -> jump = jump; this -> banana = banana; this -> year = year; this -> family = family; }
/*Member functions of DK_OOP class*/ bool Leap() { return this -> leap == "Y"; }
bool Sit() { return this -> sit == "Y"; }
bool Walk() { return this -> walk == "Y"; }
bool Swing() { return this -> swing == "Y"; } };
// filterData function void filterData(DK_OOP obj_arr[], int size){ int choice; // infinite while loop while(true){ // display the menu cout< } } // main function int main() { ifstream fin; string name, name2, sit, walk, swing, leap, family; int jump, banana, year; // Open KongCrew.txt file for reading data fin.open("KongCrew.txt"); // Make an array of objects of DK_OOP DK_OOP obj_arr[100]; int index = 0; // Read data in array of objects while (fin >> name >> name2 >> sit >> walk >> swing >> leap >> jump >> banana >> year >> family) { DK_OOP dk(name + " " + name2, sit, walk, swing, leap, jump, banana, year, family); obj_arr[index++] = dk; } // To print whole list of data cout << "Name\t\tSit\tWalk\tSwing\tLeap\tJump\tBanana\tYear\tFamily "; for (int i = 0; i < index; i++) { // Print data cout << left << setw(15) << obj_arr[i].name << "\t" << obj_arr[i].sit << "\t" << obj_arr[i].walk << "\t" << obj_arr[i].swing << "\t" << obj_arr[i].leap << "\t" << obj_arr[i].jump << "\t" << obj_arr[i].banana << "\t" << obj_arr[i].year << "\t" << obj_arr[i].family << endl; } // call to filterData function filterData(obj_arr,index); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
