www.vustudents.ning.com

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

# CS201 Introduction to Programming Assignment No 03 Fall 2020 Solution & Discussion

CS201 Introduction to Programming Assignment No 03 Fall 2020 Solution & Discussion

Views: 697

### Replies to This Discussion

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

CS201-Assign#3-100%-Correct-Solution

CS201_Assignment_No_03_Solution_Fall_2020

CS201_Assignment_No_03_Solution_Fall_2020

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 displayItem();
int getItemID();
float getPrice();
float getQuanitiy();
int ret_ItemID();
void updateQuantity(float q);
};
{
int price, quantity;
cout "Please enter item ID: ";
getItemID();
cin>>itemName;
price=getPrice();
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);
enter.write(reinterpret_cast<char *> (&obj), sizeof(Inventory));
enter.close();
}
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;
}
{
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)
{
if(std.ret_ItemID()==x)
{
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)
cin.ignore();
cin.get();
}
int main()
{
int id;
Inventory obj;
char ch;
do{
cout"ENTER CHOICE\n";
cout"02. DISPLAY FILE DATA\n";
cout"03. INCREASE QUANITY\n";
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_3_Sol_F20.cpp

CS201_3_Sol_F20.txt

# CS201 Assignment No 3 Solution Fall 2020 Complete Correct Solved

CS201 Assignment No. 3 Solution Fall 2020 & 2021 Complete Correct Solved

# CS201 Assignment No 3 Solution Fall 2020 Complete Correct Solved

CS201 assignment 3 solution 2021

### CS201 assignment 3 solution 2021:

cs201 assignment 3 solution 2021

cs201 assignment 3 solution 2020

cs201 assignment 3 solution

2020 cs201 assignment 3 solution fall 2020

#cs201_assignment3 #vuhelp #virtualuniversity
CS201 Assignment No.3 Solution||Spring 2020||Virtual University

20/20 marks .

CS201-Assign#3-100%-Correct-Solution

CS201-Assign#3-100%-Correct-Solution

1

2

3

4

5

## Latest Activity

5 hours ago
6 hours ago
+ M.Tariq Malik posted a discussion

### قرب کے نا وفا کے ہوتے ہیں - سارے جھگڑے انا کے ہوتے ہیں

6 hours ago
⭐ "Mannat"⭐✔️ posted a video

6 hours ago

6 hours ago

6 hours ago

6 hours ago

6 hours ago