Mira2706

struct1

Mar 2nd, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct Product
  6. {
  7.     char description[32];
  8.     int part_num;
  9.     double cost;
  10.     void create(char description_[], int num_, double cost_)
  11.     {
  12.         for(int i = 0; description_[i] != '\0'; i++)
  13.         {
  14.             description[i] = description_[i];
  15.  
  16.         }
  17.         part_num = num_;
  18.         cost = cost_;
  19.     }
  20.     void print_descr(Product p1)
  21.     {
  22.         cout << p1.description << endl;
  23.  
  24.     }
  25.     void print_num(Product p1)
  26.     {
  27.         cout << p1.part_num << endl;
  28.  
  29.     }
  30.     void print_cost(Product p1)
  31.     {
  32.         cout << p1.cost << endl;
  33.     }
  34.  
  35. };
  36.  
  37. int main()
  38. {
  39.     Product p1;
  40.     Product p2;
  41.     p1.create("headphones", 12095, 100);
  42.     p2.create("microphone", 10294, 499);
  43.     p1.print_descr(p1);
  44.     p2.print_cost(p2);
  45.  
  46.     return 0;
  47. }
Add Comment
Please, Sign In to add comment