test
This commit is contained in:
parent
37776af5db
commit
ab03d5f10c
4045 changed files with 286212 additions and 3 deletions
84
.config/Code/User/History/55a26ddb/1iQO.cpp
Normal file
84
.config/Code/User/History/55a26ddb/1iQO.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
126
.config/Code/User/History/55a26ddb/3XDB.cpp
Normal file
126
.config/Code/User/History/55a26ddb/3XDB.cpp
Normal file
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
238
.config/Code/User/History/55a26ddb/4QM8.cpp
Normal file
238
.config/Code/User/History/55a26ddb/4QM8.cpp
Normal file
|
@ -0,0 +1,238 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
cout<<"Product not found"<<endl;
|
||||
return products[0];
|
||||
}
|
||||
|
||||
float calculateInventoryValue(){
|
||||
float total = 0;
|
||||
for(int i=0;i<count;i++) total += products[i].getPrice() * products[i].getQuantity();
|
||||
return total;
|
||||
}
|
||||
|
||||
void display(){
|
||||
for(int i=0;i<count;i++){
|
||||
cout<<"ID: "<<products[i].getId()<<endl;
|
||||
cout<<"Name: "<<products[i].getName()<<endl;
|
||||
cout<<"Price: "<<products[i].getPrice()<<endl;
|
||||
cout<<"Quantity: "<<products[i].getQuantity()<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
~Inventory(){
|
||||
delete[] products;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
Inventory inventory(10);
|
||||
|
||||
int choice;
|
||||
int id, quantity;
|
||||
float price;
|
||||
char name[100];
|
||||
|
||||
bool a = true;
|
||||
while(a){
|
||||
|
||||
cout<<endl<<endl;
|
||||
cout<<"Enter 1 to add product"<<endl;
|
||||
cout<<"Enter 2 to remove product by id"<<endl;
|
||||
cout<<"Enter 3 to remove product by name"<<endl;
|
||||
cout<<"Enter 4 to remove product by id and quantity"<<endl;
|
||||
cout<<"Enter 5 to update quantity of product"<<endl;
|
||||
cout<<"Enter 6 to get product by id"<<endl;
|
||||
cout<<"Enter 7 to calculate inventory value"<<endl;
|
||||
cout<<"Enter 8 to display inventory"<<endl;
|
||||
cout<<"Enter 0 to exit"<<endl;
|
||||
cin>>choice;
|
||||
|
||||
switch(choice){
|
||||
case 1:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
cout<<"Enter price: ";
|
||||
cin>>price;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.addProduct(id, name, price, quantity);
|
||||
break;
|
||||
case 2:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
inventory.removeProduct(id);
|
||||
break;
|
||||
case 3:
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
inventory.removeProduct(name);
|
||||
break;
|
||||
case 4:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.removeProduct(id, quantity);
|
||||
break;
|
||||
case 5:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity change: ";
|
||||
cin>>quantity;
|
||||
inventory.updateQuantity(id, quantity);
|
||||
break;
|
||||
case 6:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"ID: "<<inventory.getProduct(id).getId()<<endl;
|
||||
cout<<"Name: "<<inventory.getProduct(id).getName()<<endl;
|
||||
cout<<"Price: "<<inventory.getProduct(id).getPrice()<<endl;
|
||||
cout<<"Quantity: "<<inventory.getProduct(id).getQuantity()<<endl;
|
||||
break;
|
||||
case 7:
|
||||
cout<<"Inventory value: "<<inventory.calculateInventoryValue()<<endl;
|
||||
break;
|
||||
case 8: inventory.display();
|
||||
break;
|
||||
case 0: a = false;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
116
.config/Code/User/History/55a26ddb/4qEk.cpp
Normal file
116
.config/Code/User/History/55a26ddb/4qEk.cpp
Normal file
|
@ -0,0 +1,116 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
135
.config/Code/User/History/55a26ddb/6Oz1.cpp
Normal file
135
.config/Code/User/History/55a26ddb/6Oz1.cpp
Normal file
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
76
.config/Code/User/History/55a26ddb/6uym.cpp
Normal file
76
.config/Code/User/History/55a26ddb/6uym.cpp
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
32
.config/Code/User/History/55a26ddb/7VKQ.cpp
Normal file
32
.config/Code/User/History/55a26ddb/7VKQ.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
144
.config/Code/User/History/55a26ddb/7edg.cpp
Normal file
144
.config/Code/User/History/55a26ddb/7edg.cpp
Normal file
|
@ -0,0 +1,144 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
253
.config/Code/User/History/55a26ddb/8aSp.cpp
Normal file
253
.config/Code/User/History/55a26ddb/8aSp.cpp
Normal file
|
@ -0,0 +1,253 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float calculateInventoryValue(){
|
||||
float total = 0;
|
||||
for(int i=0;i<count;i++) total += products[i].getPrice() * products[i].getQuantity();
|
||||
return total;
|
||||
}
|
||||
|
||||
void display(){
|
||||
for(int i=0;i<count;i++){
|
||||
cout<<"ID: "<<products[i].getId()<<endl;
|
||||
cout<<"Name: "<<products[i].getName()<<endl;
|
||||
cout<<"Price: "<<products[i].getPrice()<<endl;
|
||||
cout<<"Quantity: "<<products[i].getQuantity()<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
~Inventory(){
|
||||
delete[] products;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
// user interface to interact with classes and also take input
|
||||
Inventory inventory(10);
|
||||
cout<<"Enter 1 to add product"<<endl;
|
||||
cout<<"Enter 2 to remove product by id"<<endl;
|
||||
cout<<"Enter 3 to remove product by name"<<endl;
|
||||
cout<<"Enter 4 to remove product by id and quantity"<<endl;
|
||||
cout<<"Enter 5 to update quantity of product"<<endl;
|
||||
cout<<"Enter 6 to get product by id"<<endl;
|
||||
cout<<"Enter 7 to calculate inventory value"<<endl;
|
||||
cout<<"Enter 8 to display inventory"<<endl;
|
||||
cout<<"Enter 0 to exit"<<endl;
|
||||
int choice;
|
||||
|
||||
// swithc no curlies afte cases
|
||||
while(true){
|
||||
cin>>choice;
|
||||
switch(choice){
|
||||
case 1:
|
||||
{
|
||||
int id, quantity;
|
||||
float price;
|
||||
char name[100];
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
cout<<"Enter price: ";
|
||||
cin>>price;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.addProduct(id, name, price, quantity);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
int id;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
inventory.removeProduct(id);
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
char name[100];
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
inventory.removeProduct(name);
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
int id, quantity;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.removeProduct(id, quantity);
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
int id, quantity;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity change: ";
|
||||
cin>>quantity;
|
||||
inventory.updateQuantity(id, quantity);
|
||||
break;
|
||||
}
|
||||
case 6:
|
||||
{
|
||||
int id;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
Product product = inventory.getProduct(id);
|
||||
cout<<"ID: "<<product.getId()<<endl;
|
||||
cout<<"Name: "<<product.getName()<<endl;
|
||||
cout<<"Price: "<<product.getPrice()<<endl;
|
||||
cout<<"Quantity: "<<product.getQuantity()<<endl;
|
||||
break;
|
||||
}
|
||||
case 7:
|
||||
cout<<"Inventory value: "<<inventory.calculateInventoryValue()<<endl;
|
||||
break;
|
||||
case 8:
|
||||
inventory.display();
|
||||
break;
|
||||
case 0:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
235
.config/Code/User/History/55a26ddb/Aqft.cpp
Normal file
235
.config/Code/User/History/55a26ddb/Aqft.cpp
Normal file
|
@ -0,0 +1,235 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float calculateInventoryValue(){
|
||||
float total = 0;
|
||||
for(int i=0;i<count;i++) total += products[i].getPrice() * products[i].getQuantity();
|
||||
return total;
|
||||
}
|
||||
|
||||
void display(){
|
||||
for(int i=0;i<count;i++){
|
||||
cout<<"ID: "<<products[i].getId()<<endl;
|
||||
cout<<"Name: "<<products[i].getName()<<endl;
|
||||
cout<<"Price: "<<products[i].getPrice()<<endl;
|
||||
cout<<"Quantity: "<<products[i].getQuantity()<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
~Inventory(){
|
||||
delete[] products;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
// user interface to interact with classes and also take input
|
||||
Inventory inventory(10);
|
||||
cout<<"Enter 1 to add product"<<endl;
|
||||
cout<<"Enter 2 to remove product by id"<<endl;
|
||||
cout<<"Enter 3 to remove product by name"<<endl;
|
||||
cout<<"Enter 4 to remove product by id and quantity"<<endl;
|
||||
cout<<"Enter 5 to update quantity of product"<<endl;
|
||||
cout<<"Enter 6 to get product by id"<<endl;
|
||||
cout<<"Enter 7 to calculate inventory value"<<endl;
|
||||
cout<<"Enter 8 to display inventory"<<endl;
|
||||
cout<<"Enter 0 to exit"<<endl;
|
||||
int choice;
|
||||
int id, quantity;
|
||||
float price;
|
||||
char name[100];
|
||||
|
||||
while(true){
|
||||
cin>>choice;
|
||||
switch(choice){
|
||||
case 1:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
cout<<"Enter price: ";
|
||||
cin>>price;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.addProduct(id, name, price, quantity);
|
||||
break;
|
||||
case 2:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
inventory.removeProduct(id);
|
||||
break;
|
||||
case 3:
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
inventory.removeProduct(name);
|
||||
break;
|
||||
case 4:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.removeProduct(id, quantity);
|
||||
break;
|
||||
case 5:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity change: ";
|
||||
cin>>quantity;
|
||||
inventory.updateQuantity(id, quantity);
|
||||
break;
|
||||
case 6:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
Product product = inventory.getProduct(id);
|
||||
cout<<"ID: "<<product.getId()<<endl;
|
||||
cout<<"Name: "<<product.getName()<<endl;
|
||||
cout<<"Price: "<<product.getPrice()<<endl;
|
||||
cout<<"Quantity: "<<product.getQuantity()<<endl;
|
||||
break;
|
||||
case 7:
|
||||
cout<<"Inventory value: "<<inventory.calculateInventoryValue()<<endl;
|
||||
break;
|
||||
case 8:
|
||||
inventory.display();
|
||||
break;
|
||||
case 0:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
27
.config/Code/User/History/55a26ddb/ArUH.cpp
Normal file
27
.config/Code/User/History/55a26ddb/ArUH.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
class InventoryManagement{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
239
.config/Code/User/History/55a26ddb/BQ8G.cpp
Normal file
239
.config/Code/User/History/55a26ddb/BQ8G.cpp
Normal file
|
@ -0,0 +1,239 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
Assignment 3
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
cout<<"Product not found"<<endl;
|
||||
return products[0];
|
||||
}
|
||||
|
||||
float calculateInventoryValue(){
|
||||
float total = 0;
|
||||
for(int i=0;i<count;i++) total += products[i].getPrice() * products[i].getQuantity();
|
||||
return total;
|
||||
}
|
||||
|
||||
void display(){
|
||||
for(int i=0;i<count;i++){
|
||||
cout<<"ID: "<<products[i].getId()<<endl;
|
||||
cout<<"Name: "<<products[i].getName()<<endl;
|
||||
cout<<"Price: "<<products[i].getPrice()<<endl;
|
||||
cout<<"Quantity: "<<products[i].getQuantity()<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
~Inventory(){
|
||||
delete[] products;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
Inventory inventory(10);
|
||||
|
||||
int choice;
|
||||
int id, quantity;
|
||||
float price;
|
||||
char name[100];
|
||||
|
||||
bool a = true;
|
||||
while(a){
|
||||
|
||||
cout<<endl<<endl;
|
||||
cout<<"Enter 1 to add product"<<endl;
|
||||
cout<<"Enter 2 to remove product by id"<<endl;
|
||||
cout<<"Enter 3 to remove product by name"<<endl;
|
||||
cout<<"Enter 4 to remove product by id and quantity"<<endl;
|
||||
cout<<"Enter 5 to update quantity of product"<<endl;
|
||||
cout<<"Enter 6 to get product by id"<<endl;
|
||||
cout<<"Enter 7 to calculate inventory value"<<endl;
|
||||
cout<<"Enter 8 to display inventory"<<endl;
|
||||
cout<<"Enter 0 to exit"<<endl;
|
||||
cin>>choice;
|
||||
|
||||
switch(choice){
|
||||
case 1:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
cout<<"Enter price: ";
|
||||
cin>>price;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.addProduct(id, name, price, quantity);
|
||||
break;
|
||||
case 2:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
inventory.removeProduct(id);
|
||||
break;
|
||||
case 3:
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
inventory.removeProduct(name);
|
||||
break;
|
||||
case 4:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.removeProduct(id, quantity);
|
||||
break;
|
||||
case 5:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity change: ";
|
||||
cin>>quantity;
|
||||
inventory.updateQuantity(id, quantity);
|
||||
break;
|
||||
case 6:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"ID: "<<inventory.getProduct(id).getId()<<endl;
|
||||
cout<<"Name: "<<inventory.getProduct(id).getName()<<endl;
|
||||
cout<<"Price: "<<inventory.getProduct(id).getPrice()<<endl;
|
||||
cout<<"Quantity: "<<inventory.getProduct(id).getQuantity()<<endl;
|
||||
break;
|
||||
case 7:
|
||||
cout<<"Inventory value: "<<inventory.calculateInventoryValue()<<endl;
|
||||
break;
|
||||
case 8: inventory.display();
|
||||
break;
|
||||
case 0: a = false;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
86
.config/Code/User/History/55a26ddb/FCIF.cpp
Normal file
86
.config/Code/User/History/55a26ddb/FCIF.cpp
Normal file
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count < size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else{
|
||||
cout << "Inventory is full" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
237
.config/Code/User/History/55a26ddb/GIim.cpp
Normal file
237
.config/Code/User/History/55a26ddb/GIim.cpp
Normal file
|
@ -0,0 +1,237 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
cout<<"Product not found"<<endl;
|
||||
return products[0];
|
||||
}
|
||||
|
||||
float calculateInventoryValue(){
|
||||
float total = 0;
|
||||
for(int i=0;i<count;i++) total += products[i].getPrice() * products[i].getQuantity();
|
||||
return total;
|
||||
}
|
||||
|
||||
void display(){
|
||||
for(int i=0;i<count;i++){
|
||||
cout<<"ID: "<<products[i].getId()<<endl;
|
||||
cout<<"Name: "<<products[i].getName()<<endl;
|
||||
cout<<"Price: "<<products[i].getPrice()<<endl;
|
||||
cout<<"Quantity: "<<products[i].getQuantity()<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
~Inventory(){
|
||||
delete[] products;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
Inventory inventory(10);
|
||||
|
||||
int choice;
|
||||
int id, quantity;
|
||||
float price;
|
||||
char name[100];
|
||||
|
||||
while(true){
|
||||
|
||||
cout<<endl<<endl;
|
||||
cout<<"Enter 1 to add product"<<endl;
|
||||
cout<<"Enter 2 to remove product by id"<<endl;
|
||||
cout<<"Enter 3 to remove product by name"<<endl;
|
||||
cout<<"Enter 4 to remove product by id and quantity"<<endl;
|
||||
cout<<"Enter 5 to update quantity of product"<<endl;
|
||||
cout<<"Enter 6 to get product by id"<<endl;
|
||||
cout<<"Enter 7 to calculate inventory value"<<endl;
|
||||
cout<<"Enter 8 to display inventory"<<endl;
|
||||
cout<<"Enter 0 to exit"<<endl;
|
||||
cin>>choice;
|
||||
|
||||
switch(choice){
|
||||
case 1:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
cout<<"Enter price: ";
|
||||
cin>>price;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.addProduct(id, name, price, quantity);
|
||||
break;
|
||||
case 2:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
inventory.removeProduct(id);
|
||||
break;
|
||||
case 3:
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
inventory.removeProduct(name);
|
||||
break;
|
||||
case 4:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.removeProduct(id, quantity);
|
||||
break;
|
||||
case 5:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity change: ";
|
||||
cin>>quantity;
|
||||
inventory.updateQuantity(id, quantity);
|
||||
break;
|
||||
case 6:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"ID: "<<inventory.getProduct(id).getId()<<endl;
|
||||
cout<<"Name: "<<inventory.getProduct(id).getName()<<endl;
|
||||
cout<<"Price: "<<inventory.getProduct(id).getPrice()<<endl;
|
||||
cout<<"Quantity: "<<inventory.getProduct(id).getQuantity()<<endl;
|
||||
break;
|
||||
case 7:
|
||||
cout<<"Inventory value: "<<inventory.calculateInventoryValue()<<endl;
|
||||
break;
|
||||
case 8: inventory.display();
|
||||
break;
|
||||
case 0: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
250
.config/Code/User/History/55a26ddb/GSgC.cpp
Normal file
250
.config/Code/User/History/55a26ddb/GSgC.cpp
Normal file
|
@ -0,0 +1,250 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float calculateInventoryValue(){
|
||||
float total = 0;
|
||||
for(int i=0;i<count;i++) total += products[i].getPrice() * products[i].getQuantity();
|
||||
return total;
|
||||
}
|
||||
|
||||
void display(){
|
||||
for(int i=0;i<count;i++){
|
||||
cout<<"ID: "<<products[i].getId()<<endl;
|
||||
cout<<"Name: "<<products[i].getName()<<endl;
|
||||
cout<<"Price: "<<products[i].getPrice()<<endl;
|
||||
cout<<"Quantity: "<<products[i].getQuantity()<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
~Inventory(){
|
||||
delete[] products;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
// user interface to interact with classes and also take input
|
||||
Inventory inventory(10);
|
||||
cout<<"Enter 1 to add product"<<endl;
|
||||
cout<<"Enter 2 to remove product by id"<<endl;
|
||||
cout<<"Enter 3 to remove product by name"<<endl;
|
||||
cout<<"Enter 4 to remove product by id and quantity"<<endl;
|
||||
cout<<"Enter 5 to update quantity of product"<<endl;
|
||||
cout<<"Enter 6 to get product by id"<<endl;
|
||||
cout<<"Enter 7 to calculate inventory value"<<endl;
|
||||
cout<<"Enter 8 to display inventory"<<endl;
|
||||
cout<<"Enter 0 to exit"<<endl;
|
||||
int choice;
|
||||
|
||||
// switch
|
||||
while(true){
|
||||
cin>>choice;
|
||||
switch(choice){
|
||||
case 1:{
|
||||
int id, quantity;
|
||||
float price;
|
||||
char name[100];
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
cout<<"Enter price: ";
|
||||
cin>>price;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.addProduct(id, name, price, quantity);
|
||||
break;
|
||||
}
|
||||
case 2:{
|
||||
int id;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
inventory.removeProduct(id);
|
||||
break;
|
||||
}
|
||||
case 3:{
|
||||
char name[100];
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
inventory.removeProduct(name);
|
||||
break;
|
||||
}
|
||||
case 4:{
|
||||
int id, quantity;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.removeProduct(id, quantity);
|
||||
break;
|
||||
}
|
||||
case 5:{
|
||||
int id, quantity;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity change: ";
|
||||
cin>>quantity;
|
||||
inventory.updateQuantity(id, quantity);
|
||||
break;
|
||||
}
|
||||
case 6:{
|
||||
int id;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
Product product = inventory.getProduct(id);
|
||||
cout<<"ID: "<<product.getId()<<endl;
|
||||
cout<<"Name: "<<product.getName()<<endl;
|
||||
cout<<"Price: "<<product.getPrice()<<endl;
|
||||
cout<<"Quantity: "<<product.getQuantity()<<endl;
|
||||
break;
|
||||
}
|
||||
case 7:{
|
||||
cout<<"Inventory value: "<<inventory.calculateInventoryValue()<<endl;
|
||||
break;
|
||||
}
|
||||
case 8:{
|
||||
inventory.display();
|
||||
break;
|
||||
}
|
||||
case 0:{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
232
.config/Code/User/History/55a26ddb/Hl7c.cpp
Normal file
232
.config/Code/User/History/55a26ddb/Hl7c.cpp
Normal file
|
@ -0,0 +1,232 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float calculateInventoryValue(){
|
||||
float total = 0;
|
||||
for(int i=0;i<count;i++) total += products[i].getPrice() * products[i].getQuantity();
|
||||
return total;
|
||||
}
|
||||
|
||||
void display(){
|
||||
for(int i=0;i<count;i++){
|
||||
cout<<"ID: "<<products[i].getId()<<endl;
|
||||
cout<<"Name: "<<products[i].getName()<<endl;
|
||||
cout<<"Price: "<<products[i].getPrice()<<endl;
|
||||
cout<<"Quantity: "<<products[i].getQuantity()<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
~Inventory(){
|
||||
delete[] products;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
Inventory inventory(10);
|
||||
|
||||
int choice;
|
||||
int id, quantity;
|
||||
float price;
|
||||
char name[100];
|
||||
|
||||
while(true){
|
||||
cout<<"Enter 1 to add product"<<endl;
|
||||
cout<<"Enter 2 to remove product by id"<<endl;
|
||||
cout<<"Enter 3 to remove product by name"<<endl;
|
||||
cout<<"Enter 4 to remove product by id and quantity"<<endl;
|
||||
cout<<"Enter 5 to update quantity of product"<<endl;
|
||||
cout<<"Enter 6 to get product by id"<<endl;
|
||||
cout<<"Enter 7 to calculate inventory value"<<endl;
|
||||
cout<<"Enter 8 to display inventory"<<endl;
|
||||
cout<<"Enter 0 to exit"<<endl;
|
||||
cin>>choice;
|
||||
switch(choice){
|
||||
case 1:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
cout<<"Enter price: ";
|
||||
cin>>price;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.addProduct(id, name, price, quantity);
|
||||
break;
|
||||
case 2:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
inventory.removeProduct(id);
|
||||
break;
|
||||
case 3:
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
inventory.removeProduct(name);
|
||||
break;
|
||||
case 4:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.removeProduct(id, quantity);
|
||||
break;
|
||||
case 5:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity change: ";
|
||||
cin>>quantity;
|
||||
inventory.updateQuantity(id, quantity);
|
||||
break;
|
||||
case 6:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"ID: "<<inventory.getProduct(id).getId()<<endl;
|
||||
cout<<"Name: "<<inventory.getProduct(id).getName()<<endl;
|
||||
cout<<"Price: "<<inventory.getProduct(id).getPrice()<<endl;
|
||||
cout<<"Quantity: "<<inventory.getProduct(id).getQuantity()<<endl;
|
||||
break;
|
||||
case 7:
|
||||
cout<<"Inventory value: "<<inventory.calculateInventoryValue()<<endl;
|
||||
break;
|
||||
case 8: inventory.display();
|
||||
break;
|
||||
case 0: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
33
.config/Code/User/History/55a26ddb/I5Vz.cpp
Normal file
33
.config/Code/User/History/55a26ddb/I5Vz.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class InventoryManagement{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
// Constructor using member initializer list and lenstr and srccpy functions
|
||||
InventoryManagement(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
143
.config/Code/User/History/55a26ddb/JWzK.cpp
Normal file
143
.config/Code/User/History/55a26ddb/JWzK.cpp
Normal file
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
13
.config/Code/User/History/55a26ddb/KUZE.cpp
Normal file
13
.config/Code/User/History/55a26ddb/KUZE.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
126
.config/Code/User/History/55a26ddb/MO5r.cpp
Normal file
126
.config/Code/User/History/55a26ddb/MO5r.cpp
Normal file
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count0){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
74
.config/Code/User/History/55a26ddb/Nif8.cpp
Normal file
74
.config/Code/User/History/55a26ddb/Nif8.cpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
235
.config/Code/User/History/55a26ddb/QC8I.cpp
Normal file
235
.config/Code/User/History/55a26ddb/QC8I.cpp
Normal file
|
@ -0,0 +1,235 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float calculateInventoryValue(){
|
||||
float total = 0;
|
||||
for(int i=0;i<count;i++) total += products[i].getPrice() * products[i].getQuantity();
|
||||
return total;
|
||||
}
|
||||
|
||||
void display(){
|
||||
for(int i=0;i<count;i++){
|
||||
cout<<"ID: "<<products[i].getId()<<endl;
|
||||
cout<<"Name: "<<products[i].getName()<<endl;
|
||||
cout<<"Price: "<<products[i].getPrice()<<endl;
|
||||
cout<<"Quantity: "<<products[i].getQuantity()<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
~Inventory(){
|
||||
delete[] products;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
// user interface to interact with classes and also take input
|
||||
Inventory inventory(10);
|
||||
cout<<"Enter 1 to add product"<<endl;
|
||||
cout<<"Enter 2 to remove product by id"<<endl;
|
||||
cout<<"Enter 3 to remove product by name"<<endl;
|
||||
cout<<"Enter 4 to remove product by id and quantity"<<endl;
|
||||
cout<<"Enter 5 to update quantity of product"<<endl;
|
||||
cout<<"Enter 6 to get product by id"<<endl;
|
||||
cout<<"Enter 7 to calculate inventory value"<<endl;
|
||||
cout<<"Enter 8 to display inventory"<<endl;
|
||||
cout<<"Enter 0 to exit"<<endl;
|
||||
int choice;
|
||||
int id, quantity;
|
||||
float price;
|
||||
string name;
|
||||
|
||||
while(true){
|
||||
cin>>choice;
|
||||
switch(choice){
|
||||
case 1:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
cout<<"Enter price: ";
|
||||
cin>>price;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.addProduct(id, name, price, quantity);
|
||||
break;
|
||||
case 2:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
inventory.removeProduct(id);
|
||||
break;
|
||||
case 3:
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
inventory.removeProduct(name);
|
||||
break;
|
||||
case 4:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.removeProduct(id, quantity);
|
||||
break;
|
||||
case 5:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity change: ";
|
||||
cin>>quantity;
|
||||
inventory.updateQuantity(id, quantity);
|
||||
break;
|
||||
case 6:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
Product product = inventory.getProduct(id);
|
||||
cout<<"ID: "<<product.getId()<<endl;
|
||||
cout<<"Name: "<<product.getName()<<endl;
|
||||
cout<<"Price: "<<product.getPrice()<<endl;
|
||||
cout<<"Quantity: "<<product.getQuantity()<<endl;
|
||||
break;
|
||||
case 7:
|
||||
cout<<"Inventory value: "<<inventory.calculateInventoryValue()<<endl;
|
||||
break;
|
||||
case 8:
|
||||
inventory.display();
|
||||
break;
|
||||
case 0:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
149
.config/Code/User/History/55a26ddb/RnL9.cpp
Normal file
149
.config/Code/User/History/55a26ddb/RnL9.cpp
Normal file
|
@ -0,0 +1,149 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float calculateInventoryValue(){
|
||||
float total = 0;
|
||||
for(int i=0;i<count;i++) total += products[i].getPrice() * products[i].getQuantity();
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
236
.config/Code/User/History/55a26ddb/Rq4a.cpp
Normal file
236
.config/Code/User/History/55a26ddb/Rq4a.cpp
Normal file
|
@ -0,0 +1,236 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float calculateInventoryValue(){
|
||||
float total = 0;
|
||||
for(int i=0;i<count;i++) total += products[i].getPrice() * products[i].getQuantity();
|
||||
return total;
|
||||
}
|
||||
|
||||
void display(){
|
||||
for(int i=0;i<count;i++){
|
||||
cout<<"ID: "<<products[i].getId()<<endl;
|
||||
cout<<"Name: "<<products[i].getName()<<endl;
|
||||
cout<<"Price: "<<products[i].getPrice()<<endl;
|
||||
cout<<"Quantity: "<<products[i].getQuantity()<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
~Inventory(){
|
||||
delete[] products;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
// user interface to interact with classes and also take input
|
||||
Inventory inventory(10);
|
||||
cout<<"Enter 1 to add product"<<endl;
|
||||
cout<<"Enter 2 to remove product by id"<<endl;
|
||||
cout<<"Enter 3 to remove product by name"<<endl;
|
||||
cout<<"Enter 4 to remove product by id and quantity"<<endl;
|
||||
cout<<"Enter 5 to update quantity of product"<<endl;
|
||||
cout<<"Enter 6 to get product by id"<<endl;
|
||||
cout<<"Enter 7 to calculate inventory value"<<endl;
|
||||
cout<<"Enter 8 to display inventory"<<endl;
|
||||
cout<<"Enter 0 to exit"<<endl;
|
||||
int choice;
|
||||
int id, quantity;
|
||||
float price;
|
||||
char name[100];
|
||||
|
||||
// swithc no curlies afte cases
|
||||
while(true){
|
||||
cin>>choice;
|
||||
switch(choice){
|
||||
case 1:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
cout<<"Enter price: ";
|
||||
cin>>price;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.addProduct(id, name, price, quantity);
|
||||
break;
|
||||
case 2:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
inventory.removeProduct(id);
|
||||
break;
|
||||
case 3:
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
inventory.removeProduct(name);
|
||||
break;
|
||||
case 4:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.removeProduct(id, quantity);
|
||||
break;
|
||||
case 5:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity change: ";
|
||||
cin>>quantity;
|
||||
inventory.updateQuantity(id, quantity);
|
||||
break;
|
||||
case 6:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
Product product = inventory.getProduct(id);
|
||||
cout<<"ID: "<<product.getId()<<endl;
|
||||
cout<<"Name: "<<product.getName()<<endl;
|
||||
cout<<"Price: "<<product.getPrice()<<endl;
|
||||
cout<<"Quantity: "<<product.getQuantity()<<endl;
|
||||
break;
|
||||
case 7:
|
||||
cout<<"Inventory value: "<<inventory.calculateInventoryValue()<<endl;
|
||||
break;
|
||||
case 8:
|
||||
inventory.display();
|
||||
break;
|
||||
case 0:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
104
.config/Code/User/History/55a26ddb/SzHG.cpp
Normal file
104
.config/Code/User/History/55a26ddb/SzHG.cpp
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
235
.config/Code/User/History/55a26ddb/Tjxp.cpp
Normal file
235
.config/Code/User/History/55a26ddb/Tjxp.cpp
Normal file
|
@ -0,0 +1,235 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float calculateInventoryValue(){
|
||||
float total = 0;
|
||||
for(int i=0;i<count;i++) total += products[i].getPrice() * products[i].getQuantity();
|
||||
return total;
|
||||
}
|
||||
|
||||
void display(){
|
||||
for(int i=0;i<count;i++){
|
||||
cout<<"ID: "<<products[i].getId()<<endl;
|
||||
cout<<"Name: "<<products[i].getName()<<endl;
|
||||
cout<<"Price: "<<products[i].getPrice()<<endl;
|
||||
cout<<"Quantity: "<<products[i].getQuantity()<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
~Inventory(){
|
||||
delete[] products;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
// user interface to interact with classes and also take input
|
||||
Inventory inventory(10);
|
||||
cout<<"Enter 1 to add product"<<endl;
|
||||
cout<<"Enter 2 to remove product by id"<<endl;
|
||||
cout<<"Enter 3 to remove product by name"<<endl;
|
||||
cout<<"Enter 4 to remove product by id and quantity"<<endl;
|
||||
cout<<"Enter 5 to update quantity of product"<<endl;
|
||||
cout<<"Enter 6 to get product by id"<<endl;
|
||||
cout<<"Enter 7 to calculate inventory value"<<endl;
|
||||
cout<<"Enter 8 to display inventory"<<endl;
|
||||
cout<<"Enter 0 to exit"<<endl;
|
||||
int choice;
|
||||
int id, quantity;
|
||||
float price;
|
||||
char name[100];
|
||||
|
||||
while(true){
|
||||
cin>>choice;
|
||||
switch(choice){
|
||||
case 1:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
cout<<"Enter price: ";
|
||||
cin>>price;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.addProduct(id, name, price, quantity);
|
||||
break;
|
||||
case 2:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
inventory.removeProduct(id);
|
||||
break;
|
||||
case 3:
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
inventory.removeProduct(name);
|
||||
break;
|
||||
case 4:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.removeProduct(id, quantity);
|
||||
break;
|
||||
case 5:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity change: ";
|
||||
cin>>quantity;
|
||||
inventory.updateQuantity(id, quantity);
|
||||
break;
|
||||
case 6:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
Product product = inventory.getProduct(id);
|
||||
cout<<"ID: "<<product.getId()<<endl;
|
||||
cout<<"Name: "<<product.getName()<<endl;
|
||||
cout<<"Price: "<<product.getPrice()<<endl;
|
||||
cout<<"Quantity: "<<product.getQuantity()<<endl;
|
||||
break;
|
||||
case 7:
|
||||
cout<<"Inventory value: "<<inventory.calculateInventoryValue()<<endl;
|
||||
break;
|
||||
case 8:
|
||||
inventory.display();
|
||||
break;
|
||||
case 0:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
249
.config/Code/User/History/55a26ddb/VSXZ.cpp
Normal file
249
.config/Code/User/History/55a26ddb/VSXZ.cpp
Normal file
|
@ -0,0 +1,249 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float calculateInventoryValue(){
|
||||
float total = 0;
|
||||
for(int i=0;i<count;i++) total += products[i].getPrice() * products[i].getQuantity();
|
||||
return total;
|
||||
}
|
||||
|
||||
void display(){
|
||||
for(int i=0;i<count;i++){
|
||||
cout<<"ID: "<<products[i].getId()<<endl;
|
||||
cout<<"Name: "<<products[i].getName()<<endl;
|
||||
cout<<"Price: "<<products[i].getPrice()<<endl;
|
||||
cout<<"Quantity: "<<products[i].getQuantity()<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
~Inventory(){
|
||||
delete[] products;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
// user interface to interact with classes and also take input
|
||||
Inventory inventory(10);
|
||||
cout<<"Enter 1 to add product"<<endl;
|
||||
cout<<"Enter 2 to remove product by id"<<endl;
|
||||
cout<<"Enter 3 to remove product by name"<<endl;
|
||||
cout<<"Enter 4 to remove product by id and quantity"<<endl;
|
||||
cout<<"Enter 5 to update quantity of product"<<endl;
|
||||
cout<<"Enter 6 to get product by id"<<endl;
|
||||
cout<<"Enter 7 to calculate inventory value"<<endl;
|
||||
cout<<"Enter 8 to display inventory"<<endl;
|
||||
cout<<"Enter 0 to exit"<<endl;
|
||||
int choice;
|
||||
|
||||
// swithc no curlies afte cases
|
||||
while(true){
|
||||
cin>>choice;
|
||||
switch(choice){
|
||||
case 1:
|
||||
{
|
||||
int id, quantity;
|
||||
float price;
|
||||
char name[100];
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
cout<<"Enter price: ";
|
||||
cin>>price;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.addProduct(id, name, price, quantity);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
int id;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
inventory.removeProduct(id);
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
char name[100];
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
inventory.removeProduct(name);
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
int id, quantity;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.removeProduct(id, quantity);
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
int id, quantity;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity change: ";
|
||||
cin>>quantity;
|
||||
inventory.updateQuantity(id, quantity);
|
||||
break;
|
||||
case 6:
|
||||
int id;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
Product product = inventory.getProduct(id);
|
||||
cout<<"ID: "<<product.getId()<<endl;
|
||||
cout<<"Name: "<<product.getName()<<endl;
|
||||
cout<<"Price: "<<product.getPrice()<<endl;
|
||||
cout<<"Quantity: "<<product.getQuantity()<<endl;
|
||||
break;
|
||||
case 7:
|
||||
cout<<"Inventory value: "<<inventory.calculateInventoryValue()<<endl;
|
||||
break;
|
||||
case 8:
|
||||
inventory.display();
|
||||
break;
|
||||
case 0:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
231
.config/Code/User/History/55a26ddb/Y8OO.cpp
Normal file
231
.config/Code/User/History/55a26ddb/Y8OO.cpp
Normal file
|
@ -0,0 +1,231 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float calculateInventoryValue(){
|
||||
float total = 0;
|
||||
for(int i=0;i<count;i++) total += products[i].getPrice() * products[i].getQuantity();
|
||||
return total;
|
||||
}
|
||||
|
||||
void display(){
|
||||
for(int i=0;i<count;i++){
|
||||
cout<<"ID: "<<products[i].getId()<<endl;
|
||||
cout<<"Name: "<<products[i].getName()<<endl;
|
||||
cout<<"Price: "<<products[i].getPrice()<<endl;
|
||||
cout<<"Quantity: "<<products[i].getQuantity()<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
~Inventory(){
|
||||
delete[] products;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
Inventory inventory(10);
|
||||
cout<<"Enter 1 to add product"<<endl;
|
||||
cout<<"Enter 2 to remove product by id"<<endl;
|
||||
cout<<"Enter 3 to remove product by name"<<endl;
|
||||
cout<<"Enter 4 to remove product by id and quantity"<<endl;
|
||||
cout<<"Enter 5 to update quantity of product"<<endl;
|
||||
cout<<"Enter 6 to get product by id"<<endl;
|
||||
cout<<"Enter 7 to calculate inventory value"<<endl;
|
||||
cout<<"Enter 8 to display inventory"<<endl;
|
||||
cout<<"Enter 0 to exit"<<endl;
|
||||
int choice;
|
||||
int id, quantity;
|
||||
float price;
|
||||
char name[100];
|
||||
|
||||
while(true){
|
||||
cin>>choice;
|
||||
switch(choice){
|
||||
case 1:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
cout<<"Enter price: ";
|
||||
cin>>price;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.addProduct(id, name, price, quantity);
|
||||
break;
|
||||
case 2:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
inventory.removeProduct(id);
|
||||
break;
|
||||
case 3:
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
inventory.removeProduct(name);
|
||||
break;
|
||||
case 4:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.removeProduct(id, quantity);
|
||||
break;
|
||||
case 5:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity change: ";
|
||||
cin>>quantity;
|
||||
inventory.updateQuantity(id, quantity);
|
||||
break;
|
||||
case 6:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"ID: "<<inventory.getProduct(id).getId()<<endl;
|
||||
cout<<"Name: "<<inventory.getProduct(id).getName()<<endl;
|
||||
cout<<"Price: "<<inventory.getProduct(id).getPrice()<<endl;
|
||||
cout<<"Quantity: "<<inventory.getProduct(id).getQuantity()<<endl;
|
||||
break;
|
||||
case 7:
|
||||
cout<<"Inventory value: "<<inventory.calculateInventoryValue()<<endl;
|
||||
break;
|
||||
case 8: inventory.display();
|
||||
break;
|
||||
case 0: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
251
.config/Code/User/History/55a26ddb/YX8U.cpp
Normal file
251
.config/Code/User/History/55a26ddb/YX8U.cpp
Normal file
|
@ -0,0 +1,251 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float calculateInventoryValue(){
|
||||
float total = 0;
|
||||
for(int i=0;i<count;i++) total += products[i].getPrice() * products[i].getQuantity();
|
||||
return total;
|
||||
}
|
||||
|
||||
void display(){
|
||||
for(int i=0;i<count;i++){
|
||||
cout<<"ID: "<<products[i].getId()<<endl;
|
||||
cout<<"Name: "<<products[i].getName()<<endl;
|
||||
cout<<"Price: "<<products[i].getPrice()<<endl;
|
||||
cout<<"Quantity: "<<products[i].getQuantity()<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
~Inventory(){
|
||||
delete[] products;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
// user interface to interact with classes and also take input
|
||||
Inventory inventory(10);
|
||||
cout<<"Enter 1 to add product"<<endl;
|
||||
cout<<"Enter 2 to remove product by id"<<endl;
|
||||
cout<<"Enter 3 to remove product by name"<<endl;
|
||||
cout<<"Enter 4 to remove product by id and quantity"<<endl;
|
||||
cout<<"Enter 5 to update quantity of product"<<endl;
|
||||
cout<<"Enter 6 to get product by id"<<endl;
|
||||
cout<<"Enter 7 to calculate inventory value"<<endl;
|
||||
cout<<"Enter 8 to display inventory"<<endl;
|
||||
cout<<"Enter 0 to exit"<<endl;
|
||||
int choice;
|
||||
|
||||
// swithc no curlies afte cases
|
||||
while(true){
|
||||
cin>>choice;
|
||||
switch(choice){
|
||||
case 1:
|
||||
{
|
||||
int id, quantity;
|
||||
float price;
|
||||
char name[100];
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
cout<<"Enter price: ";
|
||||
cin>>price;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.addProduct(id, name, price, quantity);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
int id;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
inventory.removeProduct(id);
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
char name[100];
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
inventory.removeProduct(name);
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
int id, quantity;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.removeProduct(id, quantity);
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
int id, quantity;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity change: ";
|
||||
cin>>quantity;
|
||||
inventory.updateQuantity(id, quantity);
|
||||
break;
|
||||
}
|
||||
case 6:
|
||||
int id;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
Product product = inventory.getProduct(id);
|
||||
cout<<"ID: "<<product.getId()<<endl;
|
||||
cout<<"Name: "<<product.getName()<<endl;
|
||||
cout<<"Price: "<<product.getPrice()<<endl;
|
||||
cout<<"Quantity: "<<product.getQuantity()<<endl;
|
||||
break;
|
||||
case 7:
|
||||
cout<<"Inventory value: "<<inventory.calculateInventoryValue()<<endl;
|
||||
break;
|
||||
case 8:
|
||||
inventory.display();
|
||||
break;
|
||||
case 0:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
104
.config/Code/User/History/55a26ddb/cl4F.cpp
Normal file
104
.config/Code/User/History/55a26ddb/cl4F.cpp
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i; j<count-1; j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
159
.config/Code/User/History/55a26ddb/cw3V.cpp
Normal file
159
.config/Code/User/History/55a26ddb/cw3V.cpp
Normal file
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float calculateInventoryValue(){
|
||||
float total = 0;
|
||||
for(int i=0;i<count;i++) total += products[i].getPrice() * products[i].getQuantity();
|
||||
return total;
|
||||
}
|
||||
|
||||
void display(){
|
||||
for(int i=0;i<count;i++){
|
||||
cout<<"ID: "<<products[i].getId()<<endl;
|
||||
cout<<"Name: "<<products[i].getName()<<endl;
|
||||
cout<<"Price: "<<products[i].getPrice()<<endl;
|
||||
cout<<"Quantity: "<<products[i].getQuantity()<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
21
.config/Code/User/History/55a26ddb/dsMQ.cpp
Normal file
21
.config/Code/User/History/55a26ddb/dsMQ.cpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
class InventoryManagement{
|
||||
string itemID;
|
||||
string itemName;
|
||||
string itemCategory;
|
||||
int itemQuantity;
|
||||
double itemPrice;
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
241
.config/Code/User/History/55a26ddb/eSI3.cpp
Normal file
241
.config/Code/User/History/55a26ddb/eSI3.cpp
Normal file
|
@ -0,0 +1,241 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float calculateInventoryValue(){
|
||||
float total = 0;
|
||||
for(int i=0;i<count;i++) total += products[i].getPrice() * products[i].getQuantity();
|
||||
return total;
|
||||
}
|
||||
|
||||
void display(){
|
||||
for(int i=0;i<count;i++){
|
||||
cout<<"ID: "<<products[i].getId()<<endl;
|
||||
cout<<"Name: "<<products[i].getName()<<endl;
|
||||
cout<<"Price: "<<products[i].getPrice()<<endl;
|
||||
cout<<"Quantity: "<<products[i].getQuantity()<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
~Inventory(){
|
||||
delete[] products;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
// user interface to interact with classes and also take input
|
||||
Inventory inventory(10);
|
||||
cout<<"Enter 1 to add product"<<endl;
|
||||
cout<<"Enter 2 to remove product by id"<<endl;
|
||||
cout<<"Enter 3 to remove product by name"<<endl;
|
||||
cout<<"Enter 4 to remove product by id and quantity"<<endl;
|
||||
cout<<"Enter 5 to update quantity of product"<<endl;
|
||||
cout<<"Enter 6 to get product by id"<<endl;
|
||||
cout<<"Enter 7 to calculate inventory value"<<endl;
|
||||
cout<<"Enter 8 to display inventory"<<endl;
|
||||
cout<<"Enter 0 to exit"<<endl;
|
||||
int choice;
|
||||
|
||||
// swithc no curlies afte cases
|
||||
while(true){
|
||||
cin>>choice;
|
||||
switch(choice){
|
||||
case 1:
|
||||
int id, quantity;
|
||||
float price;
|
||||
char name[100];
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
cout<<"Enter price: ";
|
||||
cin>>price;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.addProduct(id, name, price, quantity);
|
||||
break;
|
||||
case 2:
|
||||
int id;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
inventory.removeProduct(id);
|
||||
break;
|
||||
case 3:
|
||||
char name[100];
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
inventory.removeProduct(name);
|
||||
break;
|
||||
case 4:
|
||||
int id, quantity;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.removeProduct(id, quantity);
|
||||
break;
|
||||
case 5:
|
||||
int id, quantity;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity change: ";
|
||||
cin>>quantity;
|
||||
inventory.updateQuantity(id, quantity);
|
||||
break;
|
||||
case 6:
|
||||
int id;
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
Product product = inventory.getProduct(id);
|
||||
cout<<"ID: "<<product.getId()<<endl;
|
||||
cout<<"Name: "<<product.getName()<<endl;
|
||||
cout<<"Price: "<<product.getPrice()<<endl;
|
||||
cout<<"Quantity: "<<product.getQuantity()<<endl;
|
||||
break;
|
||||
case 7:
|
||||
cout<<"Inventory value: "<<inventory.calculateInventoryValue()<<endl;
|
||||
break;
|
||||
case 8:
|
||||
inventory.display();
|
||||
break;
|
||||
case 0:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
1
.config/Code/User/History/55a26ddb/entries.json
Normal file
1
.config/Code/User/History/55a26ddb/entries.json
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":1,"resource":"file:///home/rafayahmad/Stuff/a3/q4.cpp","entries":[{"id":"KUZE.cpp","timestamp":1711175753783},{"id":"dsMQ.cpp","timestamp":1711175900267},{"id":"ArUH.cpp","timestamp":1711175948751},{"id":"tDF0.cpp","timestamp":1711175991143},{"id":"I5Vz.cpp","timestamp":1711176030118},{"id":"7VKQ.cpp","timestamp":1711176400302},{"id":"zH4X.cpp","timestamp":1711176448276},{"id":"hmui.cpp","timestamp":1711176482113},{"id":"Nif8.cpp","timestamp":1711176497183},{"id":"6uym.cpp","timestamp":1711176536710},{"id":"FCIF.cpp","timestamp":1711176604920},{"id":"1iQO.cpp","timestamp":1711176637040},{"id":"jbBr.cpp","timestamp":1711176668113},{"id":"cl4F.cpp","timestamp":1711176691873},{"id":"SzHG.cpp","timestamp":1711176706413},{"id":"4qEk.cpp","timestamp":1711176812565},{"id":"MO5r.cpp","timestamp":1711176878093},{"id":"3XDB.cpp","timestamp":1711176892023},{"id":"vp1l.cpp","timestamp":1711176950075},{"id":"6Oz1.cpp","timestamp":1711176972981},{"id":"JWzK.cpp","timestamp":1711176994537},{"id":"7edg.cpp","timestamp":1711177018060},{"id":"jvox.cpp","timestamp":1711177029200},{"id":"RnL9.cpp","timestamp":1711177047139},{"id":"cw3V.cpp","timestamp":1711177064545},{"id":"unGq.cpp","timestamp":1711177089971},{"id":"GSgC.cpp","timestamp":1711177205925},{"id":"8aSp.cpp","timestamp":1711177265931},{"id":"YX8U.cpp","timestamp":1711177281486},{"id":"VSXZ.cpp","timestamp":1711177294810},{"id":"eSI3.cpp","timestamp":1711177329512},{"id":"Rq4a.cpp","timestamp":1711177411947},{"id":"Tjxp.cpp","timestamp":1711177426017},{"id":"QC8I.cpp","timestamp":1711177438505},{"id":"Aqft.cpp","timestamp":1711177469476},{"id":"gecW.cpp","timestamp":1711177561653},{"id":"Y8OO.cpp","timestamp":1711177583087},{"id":"Hl7c.cpp","timestamp":1711177800904},{"id":"i3Kz.cpp","timestamp":1711177843175},{"id":"GIim.cpp","timestamp":1711177894092},{"id":"4QM8.cpp","timestamp":1711794604735},{"id":"BQ8G.cpp","timestamp":1711869522212}]}
|
234
.config/Code/User/History/55a26ddb/gecW.cpp
Normal file
234
.config/Code/User/History/55a26ddb/gecW.cpp
Normal file
|
@ -0,0 +1,234 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float calculateInventoryValue(){
|
||||
float total = 0;
|
||||
for(int i=0;i<count;i++) total += products[i].getPrice() * products[i].getQuantity();
|
||||
return total;
|
||||
}
|
||||
|
||||
void display(){
|
||||
for(int i=0;i<count;i++){
|
||||
cout<<"ID: "<<products[i].getId()<<endl;
|
||||
cout<<"Name: "<<products[i].getName()<<endl;
|
||||
cout<<"Price: "<<products[i].getPrice()<<endl;
|
||||
cout<<"Quantity: "<<products[i].getQuantity()<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
~Inventory(){
|
||||
delete[] products;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
// user interface to interact with classes and also take input
|
||||
Inventory inventory(10);
|
||||
cout<<"Enter 1 to add product"<<endl;
|
||||
cout<<"Enter 2 to remove product by id"<<endl;
|
||||
cout<<"Enter 3 to remove product by name"<<endl;
|
||||
cout<<"Enter 4 to remove product by id and quantity"<<endl;
|
||||
cout<<"Enter 5 to update quantity of product"<<endl;
|
||||
cout<<"Enter 6 to get product by id"<<endl;
|
||||
cout<<"Enter 7 to calculate inventory value"<<endl;
|
||||
cout<<"Enter 8 to display inventory"<<endl;
|
||||
cout<<"Enter 0 to exit"<<endl;
|
||||
int choice;
|
||||
int id, quantity;
|
||||
float price;
|
||||
char name[100];
|
||||
|
||||
while(true){
|
||||
cin>>choice;
|
||||
switch(choice){
|
||||
case 1:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
cout<<"Enter price: ";
|
||||
cin>>price;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.addProduct(id, name, price, quantity);
|
||||
break;
|
||||
case 2:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
inventory.removeProduct(id);
|
||||
break;
|
||||
case 3:
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
inventory.removeProduct(name);
|
||||
break;
|
||||
case 4:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.removeProduct(id, quantity);
|
||||
break;
|
||||
case 5:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity change: ";
|
||||
cin>>quantity;
|
||||
inventory.updateQuantity(id, quantity);
|
||||
break;
|
||||
case 6:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"ID: "<<inventory.getProduct(id).getId()<<endl;
|
||||
cout<<"Name: "<<inventory.getProduct(id).getName()<<endl;
|
||||
cout<<"Price: "<<inventory.getProduct(id).getPrice()<<endl;
|
||||
cout<<"Quantity: "<<inventory.getProduct(id).getQuantity()<<endl;
|
||||
break;
|
||||
case 7:
|
||||
cout<<"Inventory value: "<<inventory.calculateInventoryValue()<<endl;
|
||||
break;
|
||||
case 8:
|
||||
inventory.display();
|
||||
break;
|
||||
case 0:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
72
.config/Code/User/History/55a26ddb/hmui.cpp
Normal file
72
.config/Code/User/History/55a26ddb/hmui.cpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
235
.config/Code/User/History/55a26ddb/i3Kz.cpp
Normal file
235
.config/Code/User/History/55a26ddb/i3Kz.cpp
Normal file
|
@ -0,0 +1,235 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float calculateInventoryValue(){
|
||||
float total = 0;
|
||||
for(int i=0;i<count;i++) total += products[i].getPrice() * products[i].getQuantity();
|
||||
return total;
|
||||
}
|
||||
|
||||
void display(){
|
||||
for(int i=0;i<count;i++){
|
||||
cout<<"ID: "<<products[i].getId()<<endl;
|
||||
cout<<"Name: "<<products[i].getName()<<endl;
|
||||
cout<<"Price: "<<products[i].getPrice()<<endl;
|
||||
cout<<"Quantity: "<<products[i].getQuantity()<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
~Inventory(){
|
||||
delete[] products;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
Inventory inventory(10);
|
||||
|
||||
int choice;
|
||||
int id, quantity;
|
||||
float price;
|
||||
char name[100];
|
||||
|
||||
while(true){
|
||||
|
||||
cout<<endl<<endl;
|
||||
cout<<"Enter 1 to add product"<<endl;
|
||||
cout<<"Enter 2 to remove product by id"<<endl;
|
||||
cout<<"Enter 3 to remove product by name"<<endl;
|
||||
cout<<"Enter 4 to remove product by id and quantity"<<endl;
|
||||
cout<<"Enter 5 to update quantity of product"<<endl;
|
||||
cout<<"Enter 6 to get product by id"<<endl;
|
||||
cout<<"Enter 7 to calculate inventory value"<<endl;
|
||||
cout<<"Enter 8 to display inventory"<<endl;
|
||||
cout<<"Enter 0 to exit"<<endl;
|
||||
cin>>choice;
|
||||
|
||||
switch(choice){
|
||||
case 1:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
cout<<"Enter price: ";
|
||||
cin>>price;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.addProduct(id, name, price, quantity);
|
||||
break;
|
||||
case 2:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
inventory.removeProduct(id);
|
||||
break;
|
||||
case 3:
|
||||
cout<<"Enter name: ";
|
||||
cin>>name;
|
||||
inventory.removeProduct(name);
|
||||
break;
|
||||
case 4:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity: ";
|
||||
cin>>quantity;
|
||||
inventory.removeProduct(id, quantity);
|
||||
break;
|
||||
case 5:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"Enter quantity change: ";
|
||||
cin>>quantity;
|
||||
inventory.updateQuantity(id, quantity);
|
||||
break;
|
||||
case 6:
|
||||
cout<<"Enter id: ";
|
||||
cin>>id;
|
||||
cout<<"ID: "<<inventory.getProduct(id).getId()<<endl;
|
||||
cout<<"Name: "<<inventory.getProduct(id).getName()<<endl;
|
||||
cout<<"Price: "<<inventory.getProduct(id).getPrice()<<endl;
|
||||
cout<<"Quantity: "<<inventory.getProduct(id).getQuantity()<<endl;
|
||||
break;
|
||||
case 7:
|
||||
cout<<"Inventory value: "<<inventory.calculateInventoryValue()<<endl;
|
||||
break;
|
||||
case 8: inventory.display();
|
||||
break;
|
||||
case 0: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
92
.config/Code/User/History/55a26ddb/jbBr.cpp
Normal file
92
.config/Code/User/History/55a26ddb/jbBr.cpp
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
143
.config/Code/User/History/55a26ddb/jvox.cpp
Normal file
143
.config/Code/User/History/55a26ddb/jvox.cpp
Normal file
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
34
.config/Code/User/History/55a26ddb/tDF0.cpp
Normal file
34
.config/Code/User/History/55a26ddb/tDF0.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class InventoryManagement{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
// Constructor using member initializer list and lenstr
|
||||
InventoryManagement(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = lenstr(name);
|
||||
this->name = new char[length+1];
|
||||
for(int i=0;i<length;i++) this->name[i] = name[i];
|
||||
this->name[length] = '\0';
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
163
.config/Code/User/History/55a26ddb/unGq.cpp
Normal file
163
.config/Code/User/History/55a26ddb/unGq.cpp
Normal file
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantityChange){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()+quantityChange);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Product& getProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
return products[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float calculateInventoryValue(){
|
||||
float total = 0;
|
||||
for(int i=0;i<count;i++) total += products[i].getPrice() * products[i].getQuantity();
|
||||
return total;
|
||||
}
|
||||
|
||||
void display(){
|
||||
for(int i=0;i<count;i++){
|
||||
cout<<"ID: "<<products[i].getId()<<endl;
|
||||
cout<<"Name: "<<products[i].getName()<<endl;
|
||||
cout<<"Price: "<<products[i].getPrice()<<endl;
|
||||
cout<<"Quantity: "<<products[i].getQuantity()<<endl;
|
||||
cout<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
~Inventory(){
|
||||
delete[] products;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
135
.config/Code/User/History/55a26ddb/vp1l.cpp
Normal file
135
.config/Code/User/History/55a26ddb/vp1l.cpp
Normal file
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product() : id(0), price(0), quantity(0){
|
||||
name = nullptr;
|
||||
}
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
Product* products;
|
||||
int count;
|
||||
int size;
|
||||
|
||||
public:
|
||||
|
||||
Inventory(int size) : size(size), count(0){
|
||||
products = new Product[size];
|
||||
}
|
||||
|
||||
void addProduct(int id, char* name, float price, int quantity){
|
||||
if(count<size){
|
||||
products[count] = Product(id, name, price, quantity);
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void addProdcut(Product* product){
|
||||
if(count<size){
|
||||
products[count] = *product;
|
||||
count++;
|
||||
}
|
||||
else cout<<"Inventory is full"<<endl;
|
||||
}
|
||||
|
||||
void removeProduct(int id){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(char* name){
|
||||
for(int i=0;i<count;i++){
|
||||
if(strcmp(products[i].getName(), name)==0){
|
||||
for(int j=i;j<count-1;j++){
|
||||
products[j] = products[j+1];
|
||||
}
|
||||
count--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void removeProduct(int id, int count){
|
||||
for(int i=0;i<this->count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(products[i].getQuantity()-count);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateQuantity(int id, int quantity){
|
||||
for(int i=0;i<count;i++){
|
||||
if(products[i].getId() == id){
|
||||
products[i].setQuantity(quantity);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
64
.config/Code/User/History/55a26ddb/zH4X.cpp
Normal file
64
.config/Code/User/History/55a26ddb/zH4X.cpp
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
Rafay Ahmad
|
||||
23I-2526
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
using namespace std;
|
||||
|
||||
class Product{
|
||||
int id;
|
||||
char* name;
|
||||
float price;
|
||||
int quantity;
|
||||
|
||||
public:
|
||||
|
||||
Product(int id, char* name, float price, int quantity) : id(id), price(price), quantity(quantity){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
|
||||
~Product(){
|
||||
delete[] name;
|
||||
}
|
||||
|
||||
int getId(){
|
||||
return id;
|
||||
}
|
||||
char* getName(){
|
||||
return name;
|
||||
}
|
||||
float getPrice(){
|
||||
return price;
|
||||
}
|
||||
int getQuantity(){
|
||||
return quantity;
|
||||
}
|
||||
|
||||
void setId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
void setName(char* name){
|
||||
int length = strlen(name);
|
||||
this->name = new char[length+1];
|
||||
strcpy(this->name, name);
|
||||
}
|
||||
void setPrice(float price){
|
||||
this->price = price;
|
||||
}
|
||||
void setQuantity(int quantity){
|
||||
this->quantity = quantity;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
int main(){
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue