Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

void displayRecord(vector &items) // // Print descriptions to user, get which in

ID: 3530560 • Letter: V

Question

void displayRecord(vector &items) // // Print descriptions to user, get which index they want, then print the data for that item ONLY THING LEFT TO DO ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #include#include#include#includeusing namespace std; class Item { private: string description; int quantity; float wholesaleCost; float retailCost; string dateAdded; public: Item (string description, int quantity, float wholesaleCost, float retailCost, string dateAdded) { this->description = description; this->quantity = quantity; this->wholesaleCost = wholesaleCost; this->retailCost = retailCost; this->dateAdded = dateAdded; } void setDescription(string description) { this -> description = description; } void setQuantity(int quantity) { this -> quantity = quantity; } void setWholesaleCost (float wholesaleCost) { this->wholesaleCost = wholesaleCost; } void setRetailCost(float retailCost) { this->retailCost = retailCost; } void setDateAdded (string dateAdded) { this->dateAdded = dateAdded; } // string getDescription() { return description; } int getQuantity() { return quantity; } float getWholesaleCost () { return wholesaleCost; } float getRetailCost() { return retailCost; } string getDateAdded () { return dateAdded; } }; void addRecord( vector &items, int *count, char *answer); void changeRecord( vector &items, int *count, int *choice, char *answer); void ValidQuantity(string tmpString, bool *validation, int Qty); //Input validation void ValidCost(string tmpString, bool *validation, float cost); // " " void ValidDate(string tmpString, bool *validation); // There are some modification. Please use this version. int main () { vector items; int count=0,choice ; // for counting item recorods char answer = 'y'; addRecord( items, &count, &answer); changeRecord( items, &count,&choice, &answer); for (int i = 0; i < count ; i++) { cout << endl <<"Record #"<<(i+1); cout << endl <<(items.at(i)).getDescription(); cout << endl <<(items.at(i)).getQuantity(); cout << endl <<(items.at(i)).getWholesaleCost(); cout << endl <<(items.at(i)).getRetailCost(); cout << endl <<(items.at(i)).getDateAdded()<<endl; } cin.ignore(); cin.get(); return 0; } void addRecord( vector &items, int *count, char *answer) { Item *tempRecord = new Item("Test", 1, 2, 3, "03/07/2013"); // a temporary class for input bool validation = true ; int tmpQty; float tmpWholesale, tmpRetail; string tmpString;// convert; cout << endl <<"***************Add Record******************"; while ((*answer == 'y') || (*answer == 'Y')) { do { cout << endl <<"Enter the item description : "; getline(cin,tmpString); if (tmpString == ""|| tmpString == " ") { cout << endl <<"Invalid Input!!!"; validation =false; } else validation = true; }while (!validation); tempRecord->setDescription(tmpString); do { cout << endl << "Enter the quantity on hand : "; getline(cin, tmpString); tmpQty=atoi(tmpString.c_str()); ValidQuantity (tmpString,&validation,tmpQty); }while((!validation)); tempRecord->setQuantity(tmpQty); do { cout << endl << "Enter the Wholesale cost : "; getline(cin, tmpString); tmpWholesale = atof(tmpString.c_str()); ValidCost (tmpString,&validation,tmpWholesale); }while(!validation); tempRecord->setWholesaleCost(tmpWholesale); do { cout << endl << "Enter the Retail cost : "; getline(cin, tmpString); tmpRetail = atof(tmpString.c_str()); ValidCost (tmpString,&validation,tmpRetail); }while(!validation); tempRecord->setRetailCost(tmpRetail); do { cout << endl << "Enter the date added (mm/dd/yyyy) :"; getline(cin,tmpString); ValidDate(tmpString, &validation); if (!validation) cout << "Invalid Input!!!"; }while(!validation); tempRecord->setDateAdded(tmpString); items.push_back(*tempRecord); *count = *count + 1; cout << " Do you want to input more ?(Y/N) : "; cin.get(*answer); cin.ignore(); } } void changeRecord( vector &items, int *count, int *choice, char *answer) { bool validation = true ; Item *tempRecord = new Item("Test", 1, 2, 3, "03/07/2013"); // a temporary class for Edit int tmpQty, numField; float tmpWholesale, tmpRetail; string tmpString; for (int i = 0; i < *count ; i++) { cout << endl <<"Record #"<<(i+1); cout << endl <<(items.at(i)).getDescription(); cout << endl <<(items.at(i)).getQuantity(); cout << endl <<(items.at(i)).getWholesaleCost(); cout << endl <<(items.at(i)).getRetailCost(); cout << endl <<(items.at(i)).getDateAdded()<<endl; } do { cout << endl << "Which record do you want to edit? : "; cin >> *choice; if ((*choice<=0) ||(*choice > (*count))) { cout << " No record has the number you entered!!!"; cout << " Please try again."; } }while ((*choice<=0) ||(*choice > (*count))); cout << endl << " You chose record #"<<*choice << " to edit "; do { cout << endl << "===============Edit Record=============="; cout << endl << "1) Description "; cout << endl << "2) Quantity "; cout << endl << "3) WholesaleCost"; cout << endl << "4) RetailCost"; cout << endl << "5) DateAdded "; cout << endl << "What field do you want to modify? :"; cin >> numField; cin.ignore(); if (numField<1 || numField >5) { cout <<" Wrong choice!!!"; cout << " Please try again. "; } }while(numField<1 || numField >5); switch (numField) { case 1: { do { cout << endl <<"Enter the item description : "; getline(cin,tmpString); if (tmpString == ""|| tmpString == " ") { cout << endl <<"Invalid Input!!!"; validation =false; } else validation = true; }while(!validation); items.at((*choice)-1).setDescription(tmpString); break; } case 2:{ do { cout << endl << "Enter the quantity on hand : "; getline(cin, tmpString); tmpQty=atoi(tmpString.c_str()); ValidQuantity (tmpString,&validation,tmpQty); }while(!validation); items.at((*choice)-1).setQuantity(tmpQty); break; } case 3:{ do { cout << endl<<"Enter the wholesale cost : "; getline(cin, tmpString); tmpWholesale = atof(tmpString.c_str()); ValidCost (tmpString,&validation,tmpWholesale); }while( !validation ); items.at((*choice)-1).setWholesaleCost(tmpWholesale); break; } case 4:{ do { cout << endl << "Enter the Retail cost : "; getline(cin, tmpString); tmpRetail = atof(tmpString.c_str()); ValidCost (tmpString,&validation,tmpRetail); }while(!validation); items.at((*choice)-1).setRetailCost(tmpRetail); break; } case 5:{ do { cout << endl << "Enter the date added (mm/dd/yyyy) :"; getline(cin,tmpString); ValidDate(tmpString, &validation); if (!validation) cout << "Invalid Input!!!"; }while(!validation); items.at((*choice-1)).setDateAdded(tmpString); break; } } } void ValidQuantity(string tmpString, bool *validation, int Qty) { int i=0; if (tmpString.size()>0) { while (i < tmpString.size()) { if ( ( isdigit (tmpString.at(i)) ) && (Qty > 0) ) { i++; *validation = true; } else { cout << endl<<"Invalid Input!!! " <<"Please, enter only numbers"<<endl; *validation = false; break; } } } else { cout << endl <<"Invalid Input!!!"<<endl; *validation = false; } return ; }

Explanation / Answer

void displayRecord(vector &items) {
int index;
cout<<"Enter the index of the item";
cin>> index;
Item e = items[index];
cout<<"description: " << description <<endl;
cout<<"quantity: " << quantity <<endl;
cout<<"wholesalecost: " << wholesalecost <<endl;
cout<<"retailcost: " << retailcost <<endl;
cout<<"date added: " << dateadded <<endl;
}