Answer to Question #252670 in C++ for liena

Question #252670

Build a class Mobile with the following data members  Model (string)  Brand (string)  Price (float)  simNum(string) 1. Provide a method print setSimNum(string num) that assigns the value num to the attribute simNum 2. Provide a method getNetwork() that returns a string telling which network operator this sim is registered on e.g. Warid, Jazz, Ufone, ,etc. For this you will have to get the first 4 chacters of the simNum and find out the network. E.g. if these 4 characters are 0300 then you will return “Jazz” , if these are 0333 then you will return Ufone and so on. Also provide a method print that prints all details about the mobile 


1
Expert's answer
2021-10-17T14:00:36-0400
#include <iostream> 
#include <string> 
using namespace std; 




//Build a class Mobile with the following data members 
class Mobile{
private:
	string model;//Model (string) 
	string brand;//Brand (string) 
	float price;//Price (float) 
	string simNum;//simNum(string) 


public:


	Mobile(){}
	Mobile(string model,string brand,float price,string simNum){
		this->model=model;
		this->brand=brand;
		this->price=price;
		this->simNum=simNum;
	}


	//1. Provide a method print setSimNum(string num) that assigns the value num to the attribute simNum 
	void setSimNum(string num){
		this->simNum=num;
	}
	//2. Provide a method getNetwork() that returns a string telling which 
	//network operator this sim is registered on e.g. Warid, Jazz, Ufone, ,etc. 
	//For this you will have to get the first 4 chacters of the simNum and find 
	//out the network. E.g. if these 4 characters are 0300 then you will return 
	//“Jazz” , if these are 0333 then you will return Ufone and so on. 


	string getNetwork(){
		if(simNum[0]=='0' && simNum[1]=='3' && simNum[2]=='0' && simNum[3]=='0'){
			return "Jazz";
		}else if(simNum[0]=='0' && simNum[1]=='3' && simNum[2]=='3' && simNum[3]=='3'){
			return "Ufone";
		}
		return "Warid";
	}


	//a method print that prints all details about the mobile 
	void  printsAllDetails(){
		cout<<"Model: "<<model<<"\n";
		cout<<"Brand: "<<brand<<"\n";
		cout<<"Price: "<<price<<"\n";
		cout<<"Sim Number: "<<simNum<<"\n";
	}


};




int main(){ 


	Mobile mobile("X5","Nokia",70.99,"0300895653");
	mobile.printsAllDetails();
	cout<<"Network: "<<mobile.getNetwork()<<"\n\n";
	int l;
	cin>>l;
	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