MUstar

IoT C++ 09/14 - Product_Product.cpp

Sep 14th, 2017
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None | 0 0
  1. #include<iostream>
  2. #include<string.h>
  3. #include "Product.h"
  4. using namespace std;
  5.  
  6. Product::Product()
  7. {
  8.     cnt = 0;
  9. }
  10.  
  11. int Product::add(char add_name[100],int add_price,int add_assessment)
  12. {
  13.     if(cnt+1==MAX)
  14.         return 1;
  15.     else
  16.     {
  17.         strcpy(name[cnt],add_name);
  18.         price[cnt] = add_price;
  19.         assessment[cnt] = add_assessment;
  20.         cnt++;
  21.         return 0;
  22.     }
  23. }
  24.  
  25. void Product::del(int delnum)
  26. {
  27.     if(cnt==0)
  28.         cout<<"삭제할 값이 아무것도 없어요. 값추가해주세요."<<endl;
  29.     else if((delnum-1<0)||(delnum-1>cnt))
  30.         cout<<"입력하신 번호에 값이 없습니다. 값추가해주세요."<<endl;
  31.     else
  32.     {
  33.         for(int i=delnum-1;i<cnt-1;i++)
  34.         {
  35.             strcpy(name[i],name[i+1]);
  36.             price[i] = price[i+1];
  37.             assessment[i] = assessment[i+1];
  38.         }
  39.         cnt--;
  40.         cout<<"정상적으로 처리되었습니다."<<endl;
  41.     }
  42. }
  43.  
  44. void Product::getInfo(int num)
  45. {
  46.     cout<<"========================="<<endl;
  47.     cout<<"제품이름 : "<<name[num-1]<<endl;
  48.     cout<<"제품가격 : "<<price[num-1]<<endl;
  49.     cout<<"제품평점 : "<<assessment[num-1]<<endl;
  50.     cout<<"========================="<<endl;
  51. }
  52. void Product::compare(int stuff1,int stuff2)
  53. {
  54.     int tmp = stuff1 - 1;
  55.     Product second;
  56.     second.add(name[stuff2-1],price[stuff2-1],assessment[stuff2-1]);
  57.     if(isBetter(second))
  58.         cout<<stuff1<<"번 제품이 더 좋습니다."<<endl;
  59.     else
  60.         cout<<stuff2<<"번 제품이 더 좋습니다."<<endl;
  61. }
  62.  
  63. bool Product::isBetter(const Product &another)
  64. {
  65.     if(assessment[tmp]>another.assessment[0])
  66.         return true;
  67.     else
  68.         return false;
  69. }
  70.  
  71. void Product::print()
  72. {
  73.     cout<<"|번호/이름/가격/평점|"<<endl;
  74.     cout<<"========================="<<endl;
  75.     for(int i=0;i<cnt;i++)
  76.         cout<<"|"<<i+1<<"/"<<name[i]<<"/"<<price[i]<<"/"<<assessment[i]<<"|"<<endl;
  77.     cout<<"========================="<<endl;
  78. }
Add Comment
Please, Sign In to add comment