Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <algorithm>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. class smartphone {
  10. private:
  11. char model[20];
  12. double price;
  13. char OS[20];
  14.  
  15.  
  16. public:
  17. smartphone() { price = 0; };
  18. smartphone(const char* mModel, double pPrice, const char* oOS);
  19. smartphone(smartphone& p);
  20. ~smartphone();
  21. float getPrice();
  22. void print();
  23. void sortPrice(int aSize);
  24. void setModel(const char* mModel);
  25. void setPrice(double pPrice);
  26. void setOS(const char* oOS);
  27. };
  28.  
  29. smartphone::smartphone(const char* mModel, double pPrice, const char* oOS) {
  30. strcpy(model, mModel);
  31. price = pPrice;
  32. strcpy(OS, oOS);
  33. }
  34.  
  35. smartphone::smartphone(smartphone& p) {
  36. strcpy(model, p.model);
  37. price = p.price;
  38. strcpy(OS, p.OS);
  39.  
  40. }
  41.  
  42. smartphone::~smartphone() {
  43.  
  44.  
  45. }
  46.  
  47. void smartphone::setModel(const char* mModel) {
  48. strcpy(model, mModel);
  49.  
  50. }
  51.  
  52. void smartphone::setOS(const char* oOS) {
  53. strcpy(OS, oOS);
  54. }
  55.  
  56. void smartphone::setPrice(double pPrice) {
  57. price = pPrice;
  58. }
  59.  
  60. float smartphone::getPrice() {
  61.  
  62. return price;
  63.  
  64. }
  65.  
  66. void smartphone::print() {
  67.  
  68. cout << model << endl;
  69. cout << price << endl;
  70. cout << OS << endl;
  71. }
  72.  
  73.  
  74. void smartphone::sortPrice(int aSize) {
  75.  
  76.  
  77. double temp;
  78. char* mModel;
  79. char* oOS;
  80. double pPrice;
  81. int k = 0;
  82. smartphone t[aSize];
  83.  
  84. while(k <= aSize){
  85. cout << "Enter the parameters of the object:" << endl;
  86. cin >> *mModel >> *oOS >> pPrice;
  87. strcpy(t[k].model, mModel);
  88. strcpy(t[k].OS, oOS);
  89. t[k].price = pPrice;
  90. k++;
  91. }
  92.  
  93.  
  94.  
  95.  
  96. for(int i = 0; i < aSize; i++){
  97. if(t[i].getPrice() > t[i+1].getPrice()){
  98. temp == t[i].getPrice();
  99. t[i].getPrice() == t[i+1].getPrice();
  100. t[i+1].getPrice() == temp;
  101. }
  102.  
  103. }
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110. for (int i = 0; i < aSize; i++) {
  111. cout << t[i].getPrice() << " ";
  112. }
  113. }
  114.  
  115.  
  116. int main()
  117. {
  118.  
  119. smartphone *ptr;
  120. ptr->sortPrice(3);
  121.  
  122.  
  123.  
  124. return 0;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement