### Archive

Posts Tagged ‘C Po’

## C++ Program to work with Purchase Order Problem by using Pointers and CLASS with PUBLIC & PRIVATE Access Specifiers – Q10

Q10. Program to work with Purchase Order Problem:

Solve the following purchase order problem:
– Item list entry
– Bill generation
– Modify Item quantity purchased
– Remove Item from the list

… from College notes (BCA/MCA assignments):

```#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>

class CBills{
private:
char name[20];
int qty;
float price, net;
public:
void Getinfo();
void Modify(CBills *, int );
void Remove(CBills *, int &);
void Display() const;
};

void CBills :: Getinfo(){
cout<<"\n Enter Item Name: ";
cin>>name;
cout<<"\n Enter Item Price: ";
cin>>price;
cout<<"\n Enter Item Quantity: ";
cin>>qty;
net = price * qty;
}

void CBills :: Modify(CBills *order, int no){
char key[15];
cout<<"\n Enter the Item Name to Modify: ";
cin>>key;
for(int i=0; i<=no; i++){
if(strcmp(order[i].name, key) == 0)
break;
}
cout<<"\n Enter Item Name: ";
cin>>order[i].name;
cout<<"\n Enter Item Price: ";
cin>>order[i].price;
cout<<"\n Enter Item Quantity: ";
cin>>order[i].qty;
order[i].net = order[i].price * order[i].qty;
}

void CBills :: Remove(CBills *order, int &no){
char key[15];
cout<<"\n Enter the Item Name to Remove: ";
cin>>key;
for(int i=0; i<=no; i++){
if(strcmp(order[i].name, key) == 0)
break;
}
for(int j=i; j<=no; j++)
order[j] = order[j+1];
no--;
}

void CBills :: Display() const{
cout<<"\n\t Item Name:  "<<name;
cout<<"\n\t Item Price: "<<price;
cout<<"\n\t Item Quantity: "<<qty;
cout<<"\n\t Net Price: "<<net;
}

void main(){
CBills bills[20], bl;
int ch1, item_no = -1;
char ch2;
while(1){
clrscr();
cout<<"\n Inventory and Purchase Order Managament.";
cout<<"\n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
cout<<"\n 1 -> Get Item Details.";
cout<<"\n 2 -> Display Items.";
cout<<"\n 3 -> Modify an Item.";
cout<<"\n 4 -> Remove an Item.";
cout<<"\n 5 -> Exit.";
cin>>ch1;
switch(ch1){
case 1: // Getinfo.
while(1){
clrscr();
item_no++;
cout<<"\n Entry of Purchased Items.";
cout<<"\n ~~~~~~~~~~~~~~~~~~~~~~~~~";
cout<<"\n Item No. "<<item_no+1;
bills[item_no].Getinfo();
cout<<"\n Do you want to add more
(y/n): ";
cin>>ch2;
if(ch2 == 'n')
break;
}
break;
case 2: // Display.
clrscr();
cout<<"\n Purchase Order Details.";
cout<<"\n ~~~~~~~~~~~~~~~~~~~~~~~";						for(int i=0; i<=item_no; i++){
cout<<"\n\n Item No.: "<<i+1;
bills[i].Display();
}
break;
case 3: // Modify.
bl.Modify(bills, item_no);
cout<<"\n\n Record Modified.";
break;
case 4: // Remove.
bl.Remove(bills, item_no);
cout<<"\n\n Record Removed.";
break;
default:
exit(1);
} // end of switch.
getch();
} // end of while.
} // end of main.
```

Output:

Inventory and Purchase Order Managament.
1 -> Get Item Details.
2 -> Display Items.
3 -> Modify an Item.
4 -> Remove an Item.
5 -> Exit.

Entry of Purchased Items.

Item No. 1
Enter Item Name: Magazine

Enter Item Price: 100

Enter Item Quantity: 5

Do you want to add more (y/n): y

Entry of Purchased Items.

Item No. 2
Enter Item Name: Register

Enter Item Price: 50

Enter Item Quantity: 10

Do you want to add more (y/n): y

Entry of Purchased Items.

Item No. 3
Enter Item Name: Pen

Enter Item Price: 10

Enter Item Quantity: 20

Do you want to add more (y/n): n

```Purchase Order Details.
Item No.	Name		Price		Qty		Net Price
1		Magazine	100		5		500
2		Register	50		10		500
3		Pen		10		20		200
```

Categories: Cpp