Answer to Question #181553 in C++ for Sadiya Yusuf

Question #181553

Create a class in C++ and name it phone. Declare data members (cost of phone and number of sim slots) inside the class.

Create three objects of the Phone class: (You are going to have three brands of phone) Assign values to the data members declared

Display cost of the three objects of phone created

Display sim slots of the three objects created.



1
Expert's answer
2021-04-14T15:57:55-0400
#include <iostream>


using namespace std;


class Phone
{
private:
    float cost;
    int numberOfSimSlots;


public:
    void setCost(float cost)
    {
        this->cost = cost;
    }
    void setNumberOfSimSlots(int numberOfSimSlots)
    {
        this->numberOfSimSlots = numberOfSimSlots;
    }


    float getCost()
    {
        return cost;
    }
    int getNumberOfSimSlots()
    {
        return numberOfSimSlots;
    }


    void display()
    {
        cout << "cost: " << cost << endl;
        cout << "number of sim slots: " << numberOfSimSlots << endl << endl;
    }
};




int main()
{
    Phone siemens;
    siemens.setCost(100);
    siemens.setNumberOfSimSlots(1);


    Phone redmi;
    redmi.setCost(200);
    redmi.setNumberOfSimSlots(2);


    Phone iphone;
    iphone.setCost(300);
    iphone.setNumberOfSimSlots(2);


    cout << "Phone 1 info" << endl;
    siemens.display();


    cout << "Phone 2 info" << endl;
    redmi.display();


    cout << "Phone 3 info" << endl;
    iphone.display();


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS