Here is my code:
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
//()
char openedP='('; //open (
char closedP=')'; //close )
//end ()
//dash
char dash='-';
//end dash
class PhoneNumber
{
int countryCode;
int areaCode;
int number;
char type;
int year;
public:
PhoneNumber()
{
countryCode = 43;
areaCode = 800;
number = 8675309;
type = 'H';
year = 1981;
}
PhoneNumber(int ccode, int acode, int num,char line,int yr)
{
countryCode = ccode;
areaCode = acode;
number = num;
type = line;
year = yr;
}
PhoneNumber(int num,char line = 'B')
{
number = num;
areaCode = 800;
year = 1981;
countryCode = 43;
type = line;
}
PhoneNumber(int acode, int num, char line = 'C')
{
countryCode = 43;
year = 1981;
areaCode = acode;
number = num;
type = line;
}
void setCountry(int ccode)
{
ccode = countryCode;
}
void setArea(int acode)
{
acode = areaCode;
}
void setType(char line)
{
type = line;
}
void setYear(int yr)
{
year = yr;
}
int getCountry() const
{
return countryCode;
}
int getNumber() const
{
return number;
}
int getArea() const
{
return areaCode;
}
char getType() const
{
return type;
}
void printNumber(ostream& out) const //Prints Areacode & Phone Number
{
cout<<"The phone number is: \n";
cout<<openedP<<areaCode<<closedP<<number/10000<<dash<<number%10000<<endl;
cout<<endl;
}
void printPhoneNumberStats(ostream& out) const // prints all phone information
{
cout<<"Printing phone number stats!\n";
cout<<" Country code: "<<countryCode<<endl;
cout<<" Area code: "<<areaCode<<endl;
cout<<" Phone number: "<<number<<endl;
cout<<" Type: "<<type<<endl;
cout<<" Year: "<<year<<endl;
cout<<endl;
}
};
int main()
{
char q; //stop from quitting
PhoneNumber firstNum;
PhoneNumber secondNum(39, 415, 8675555, 'B', 2012);
PhoneNumber thirdNum(1234567);
PhoneNumber fourthNum(1234566, 'C');
PhoneNumber fifthNum(925, 4392181);
PhoneNumber sixthNum(925, 5512346, 'H');
firstNum.printNumber(cout);
firstNum.printPhoneNumberStats(cout);
secondNum.printNumber(cout);
secondNum.printPhoneNumberStats(cout);
thirdNum.printNumber(cout);
thirdNum.printPhoneNumberStats(cout);
fourthNum.printNumber(cout);
fourthNum.printPhoneNumberStats(cout);
fifthNum.printNumber(cout);
fifthNum.printPhoneNumberStats(cout);
sixthNum.printNumber(cout);
sixthNum.printPhoneNumberStats(cout);
cin>>q;
return 0;
}
Here is what the output should look like:
The phone number is:
(800)867-5309
Printing phone number stats!
Country code: 43
Area code: 800
Phone number: 8675309
Type: H
Year: 1981The phone number is:
(415)867-5555
Printing phone number stats!
Country code: 39
Area code: 415
Phone number: 8675555
Type: B
Year: 2012
There are duplicate digits in this phone number!!
I need help detecting double digits in the 7 digit phone number and printing it out.