CS201 Introduction to Programming Assignment No 03 Fall 2020 Solution & Discussion
Tags:
Share the Assignment Questions & Discuss Here....
Stay touched with this discussion, Solution idea will be uploaded as soon as possible in replies here before the due date.
CS201-Assign#3-100%-Correct-Solution
Click on the below link to download the file
CS201_Assignment_No_03_Solution_Fall_2020
Click on the below link to download the file
CS201 Assignment 3 Fall 2020 Solution idea:
Code:
#include <iostream>
#include <fstream>
using namespace std;
class Inventory
{
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);
};
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();
coutendl;
}
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;
}
cs201 assignment no 03 solution files in doc and cpp format.
CS201 Assignment No. 3 Solution Fall 2020 & 2021 Complete Correct Solved
CS201 assignment 3 solution 2021
cs201 assignment 3 solution 2020 download
cs201 assignment 3 solution 2021
cs201 assignment 3 solution 2020
cs201 assignment 3 solution
2020 cs201 assignment 3 solution fall 2020
cs201 assignment 3 solution 2020 download
#cs201_assignment3 #vuhelp #virtualuniversity
CS201 Assignment No.3 Solution||Spring 2020||Virtual University
CS201-Assign#3-100%-Correct-Solution
Click on the below link to download the file
© 2021 Created by + M.Tariq Malik.
Powered by
Promote Us | Report an Issue | Privacy Policy | Terms of Service
We are user-generated contents site. All product, videos, pictures & others contents on site don't seem to be beneath our Copyrights & belong to their respected owners & freely available on public domains. We believe in Our Policy & do according to them. If Any content is offensive in your Copyrights then please email at m.tariqmalik@gmail.com with copyright detail & We will happy to remove it immediately.
Management: Admins ::: Moderators
Awards Badges List | Moderators Group
All Members | Featured Members | Top Reputation Members | Angels Members | Intellectual Members | Criteria for Selection
Become a Team Member | Safety Guidelines for New | Site FAQ & Rules | Safety Matters | Online Safety | Rules For Blog Post