Write a program that inputs a telephone number as a string in format 00920519085 and uses function getcountrycode ,getareacode,getphonecode, to extract country code , area code , and phone code respectively from the input string.call these functions from main() to display phone no in format as +92(51) 9085.
can anybody do that
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <conio.h>
#include <string>
usingnamespace std;
int getcountrycode();
int getareacode():
int getphonecode();
int main(){
return 0;
}
#include<iostream>
#include<string>
int getcountrycode ()
{
string countryCodeInput;
/* extract the first 4 characters from input and store in countryCodeInput
* return the countryCodeInput converted to int
*/
}
int getareacode ()
{
string areaCodeInput;
/* extract characters 5-7 from input and store in areCodeInput
* return the areaCodeInput converted to int
*/
}
int getphonecode ()
{
string phoneInput;
/* extract the last 4 characters from input and store in phoneInput
* return the phoneInput converted to int
*/
}
usingnamespace std;
string input;
int main ()
{
cout << "Phone demo\n";
cout << "----------\n";
cout << "\nEnter the phone number";
cin >> input;
int areaCode = getareacode ();
int countryCode = getcountrycode ();
int phoneNumber = getphonecode ();
// TO DO display the phone number
return 0;
}
You need to use the substring function of the string to extract the characters you want + stoi to convert your string to int.
Pick apart your instructions. It says first that you will get input in the format of 00920519085. So you start knowing what to start with. I would hard code this to start with and worry how to do the input later. Next it tells you to write three functions to take apart your input. Looking at the output changing the country code and area code to "ints" would get rid of leading zeros when printed. And the last part shows you what the output will look like.
The struct works, but simple variables in main will work fine. Your last output line will work, but does not match format as +92(51) 9085. Just going by the instructions.