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.
#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;
}
Comments
Leave a comment