Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <string.h>
- #include <algorithm>
- using namespace std;
- class smartphone {
- private:
- char model[20];
- double price;
- char OS[20];
- public:
- smartphone() { price = 0; };
- smartphone(const char* mModel, double pPrice, const char* oOS);
- smartphone(smartphone& p);
- ~smartphone();
- float getPrice();
- void print();
- void sortPrice(int aSize);
- void setModel(const char* mModel);
- void setPrice(double pPrice);
- void setOS(const char* oOS);
- };
- smartphone::smartphone(const char* mModel, double pPrice, const char* oOS) {
- strcpy(model, mModel);
- price = pPrice;
- strcpy(OS, oOS);
- }
- smartphone::smartphone(smartphone& p) {
- strcpy(model, p.model);
- price = p.price;
- strcpy(OS, p.OS);
- }
- smartphone::~smartphone() {
- }
- void smartphone::setModel(const char* mModel) {
- strcpy(model, mModel);
- }
- void smartphone::setOS(const char* oOS) {
- strcpy(OS, oOS);
- }
- void smartphone::setPrice(double pPrice) {
- price = pPrice;
- }
- float smartphone::getPrice() {
- return price;
- }
- void smartphone::print() {
- cout << model << endl;
- cout << price << endl;
- cout << OS << endl;
- }
- void smartphone::sortPrice(int aSize) {
- double temp;
- char* mModel;
- char* oOS;
- double pPrice;
- int k = 0;
- smartphone t[aSize];
- while(k <= aSize){
- cout << "Enter the parameters of the object:" << endl;
- cin >> *mModel >> *oOS >> pPrice;
- strcpy(t[k].model, mModel);
- strcpy(t[k].OS, oOS);
- t[k].price = pPrice;
- k++;
- }
- for(int i = 0; i < aSize; i++){
- if(t[i].getPrice() > t[i+1].getPrice()){
- temp == t[i].getPrice();
- t[i].getPrice() == t[i+1].getPrice();
- t[i+1].getPrice() == temp;
- }
- }
- for (int i = 0; i < aSize; i++) {
- cout << t[i].getPrice() << " ";
- }
- }
- int main()
- {
- smartphone *ptr;
- ptr->sortPrice(3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement