Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------lib.h--------------------
- #ifndef lib_h
- #define lib_h
- #include "product.h"
- class function
- {
- public:
- unsigned int GetPrice();
- void Sort(int count2);
- void SetToZero(int selection, int count2);
- unsigned int FindLowest(int count2);
- };
- #endif
- ---------------product.h----------------
- #ifndef PRODUCT_H
- #define PRODUCT_H
- class product1
- {
- public:
- int id;
- unsigned int price;
- }productss[10];
- #endif
- -------------lib.cpp--------------------
- #include "product.h"
- #include "lib.h"
- #include <iostream>
- using namespace std;
- #pragma once
- unsigned int function::GetPrice()
- {
- int productchoice=0;
- int tempvaule=0;
- cout << "Please enter in a ID" << endl;
- cin >> productchoice;
- cout << "your price for that item is" << endl;
- cin >> productss[productchoice].price;
- tempvaule=productss[productchoice].price;
- return tempvaule;
- }
- void function::Sort(int count2)
- {
- int i,j;
- for(i=0;i<count2;i++)
- {
- for(j=0;j<i;j++)
- {
- if(productss[i].id<productss[j].id)
- {
- int temp=productss[i].id;
- int temp1=productss[i].price;
- productss[i].id=productss[j].id;
- productss[i].price=productss[j].price;
- productss[j].id=temp;
- productss[j].price=temp1;
- }
- }
- }
- }
- void function::SetToZero(int selection,int count2)
- {
- productss[selection].id=0;
- productss[selection].price=0;
- int i = selection;
- int j = i;
- while (i<count2)
- {
- if (productss[i].id == 0)
- {
- j++;
- int temp = productss[j].id;
- int temp1 = productss[j].price;
- productss[i].id = temp;
- productss[i].price = temp1;
- }
- i++;
- }
- }
- unsigned int function::FindLowest(int count2)
- {
- int i;
- unsigned int tempprice=100;
- for(i=0;i<count2;i++)
- {
- if(productss[i].price<tempprice)
- {
- tempprice=productss[i].price;
- }
- }
- return tempprice;
- }
- -------------practical.cpp------------
- #include "product.h"
- #include "lib.h"
- #include <iostream>
- using namespace std;
- int main ()
- {
- function fun;
- int selection = 0;
- int productnumber=0;
- int count2 =0;
- do{
- cout << endl;
- cout << "Enter a menu aoption" << endl;
- cout << "1 = Add new item" << endl;
- cout << "2 = Print items" << endl;
- cout << "3 = Find a price" << endl;
- cout << "4 = Sort by ID" << endl;
- cout << "5 = Delete by ID" << endl;
- cout << "6 = Find the Lowest Price" << endl;
- cout << "7 = Exit" << endl << endl;;
- cin >> selection;
- if(selection==1)
- {
- cout << "Enter the the new ID" << endl;
- cin >> productss[count2].id;
- cout << "Enter the the new price" << endl;
- cin >> productss[count2].price;
- count2++;
- }
- else if(selection==2)
- {
- int count =0;
- cout <<"ID PRICE";
- cout <<"" << endl;
- while(count<count2)
- {
- cout <<productss[count].id;
- cout <<" ";
- cout <<productss[count].price << endl;
- count++;
- }
- }
- else if(selection==3)
- {
- int pricematch = fun.GetPrice();
- }
- else if(selection==4)
- {
- cout <<"Sorting by ID" << endl;
- fun.Sort(count2);
- cout <<"Sorted!" << endl;
- }
- else if(selection==5)
- {
- int selection=0;
- cout <<"Please select an Id to delete" << endl;
- cin >> selection;
- fun.SetToZero(selection,count2);
- }
- else if(selection==6)
- {
- unsigned int lowestprice = fun.FindLowest(count2);
- cout << "lowest price is";
- cout << lowestprice;
- }
- }
- while(selection!=7);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment