Answer to Question #252242 in C++ for Flying Bird

Question #252242

1.    Using C++  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.


1
Expert's answer
2021-10-16T13:53:21-0400
#include<iostream>
#include<string>
using namespace std;
class Mobile{
	private:
	string	Model;
	string Brand;
	float Price;
	string simNum;
	public:
  void setSimNum(string num){
  	simNum = num;
  }
  
  string getNetwork(){
  char first	= simNum[0];
  char second	= simNum[1];
  char third	= simNum[2];
  char fourth	= simNum[3];
  if(first=='0' && second=='3' && third=='0' && fourth=='0'){
  	return "Jazz";
  	
  }
  else if(first=='0' && second=='3' && third=='3' && fourth=='3'){
  	return "Ufone";
  }
  }




};


int main(){
	Mobile m;
	m.setSimNum("0300");
	cout<<m.getNetwork()<<endl;
}

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