-->

CS 201 Introduction Programming Assignment No 3 Solution fall 2021/20-||VU||Virtual Universe

cs201 assignment no 3 solution 2021, cs201 assignment 1 solution 2021 pdf, cs601 assignment 3 solution 2021, cs201 assignment 3 solution 2020,

 Today we solve CS 201 Assignment no 3 - but you must first support us on social networks so that you get 24 hours updates. I hope you understand the whole Assignment and Quiz, GDB. And if you have any opinion about this Assignment, you can tell in our comment section.CS 201 Assignment Solution fall 2021 Idea. Don't copy the same because the mark is zero.MGT 60 Assignment No 2 solution fall 2021.


CS 201 Assignment 3 soultion fall 2021

CS 201 Assignment Soultion :

/* CS 201 Assignment 3 Soultion Fall 2021 ||VU||Virtuial Universe */ #include <iostream> #include <fstream> using namespace std; class Inventory { //Given Solution file CS 201 //100% Correct Soultion File private: int itemID; char itemName[20]; float itemPrice; float quanitity; float totalPrice; public: void readItems(); void displayItem(); int getItemID(); float getPrice(); float getQuanitiy(); int ret_ItemID(); void updateQuantity(float q); }; //Change Your Requirment void Inventory::readItems() { int price, quantity; cout <<"Please enter item ID: "; getItemID(); cout<<"Please enter item name: "; cin>>itemName; cout<<"Please enter item price: "; price=getPrice(); cout<<"Please enter item quanity: "; quantity=getQuanitiy(); totalPrice=price*quantity; } float Inventory::getPrice() { cin>>itemPrice; return itemPrice; } int Inventory::getItemID() { cin>>itemID; return itemID; } float Inventory::getQuanitiy() { cin>>quanitity; return quanitity; } int Inventory :: ret_ItemID() { return itemID; } void appendToFile() { Inventory obj; ofstream enter; enter.open("inventory.txt",ios::app); obj.readItems(); enter.write(reinterpret_cast<char *> (&obj), sizeof(Inventory)); enter.close(); cout<<"Inventry record added successfully "; } void displayAll() { Inventory st; ifstream inFile; inFile.open("inventory.txt"); if(!inFile) { cout<<"File could not be open !! press any key............."; cin.ignore(); cin.get(); return; } while(inFile.read(reinterpret_cast<char *> (&st), sizeof(Inventory))) { st.displayItem(); cout<<endl; } inFile.close(); cin.ignore(); cin.get(); } void Inventory::displayItem() { cout<<"ItemID:"<<itemID; cout<<"\tItem Name:"<<itemName; cout<<"\tItem Price:"<<itemPrice; cout<<"\tItemQuantity:"<<quanitity; cout<<"\tTotal Price:"<<totalPrice; } void increaseQuanity(int x) { bool found=false; Inventory std; float quantity; fstream file; file.open("inventory.txt"); if(!file) { cout<<"File could not be open !! Press any key............"; cin.ignore(); cin.get(); return; } while(!file.eof() && found==false) { file.read(reinterpret_cast<char *> (&std), sizeof(Inventory)); if(std.ret_ItemID()==x) { cout<<"Add Quantity: "; std.getQuanitiy(); int pos=(-1)*static_cast<int>(sizeof(std)); file.seekp(pos,ios::cur); file.write(reinterpret_cast<char *> (&std), sizeof(Inventory)); cout<<"Item Quantity updated successfully"<<endl; found=true; } } file.close(); if(found==false) cout<<"\n\n Record Not Found "; cin.ignore(); cin.get(); } int main() { int id; Inventory obj; char ch; do{ cout<<"ENTER CHOICE\n"; cout<<"01. ADD AN INVENTORY ITEM\n"; cout<<"02. DISPLAY FILE DATA\n"; cout<<"03. INCREASE QUANITY\n"; cout<<"Please enter your choice: "; cin>>ch; switch(ch) { case '1': appendToFile(); break; case '2': displayAll(); break; case '3': cout<<"Enter Item ID: "; cin>>id; increaseQuanity(id); break; case 'y': break; default : cout<<"Enter valid number"<<endl; } } while(ch != 'y'); return 0; } //Please Subscibe my channel

Output:





You may like these posts

  1. To insert a code use <i rel="pre">code_here</i>
  2. To insert a quote use <b rel="quote">your_qoute</b>
  3. To insert a picture use <i rel="image">url_image_here</i>
Please Don't enter any spam link In the comment box.