1,105,450 Community Members

Need a little help

Member Avatar
shywolf91
Newbie Poster
12 posts since Sep 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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: 1981

The 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.

Member Avatar
Topi Ojala
Junior Poster in Training
66 posts since May 2009
Reputation Points: 2 [?]
Q&As Helped to Solve: 21 [?]
Skill Endorsements: 0 [?]
 
0
 

Implement a function which iterates over the 7 digit phone number (one digit at a time) and checks if it's the same as the digit before. I suggest converting the phonenumber to string for easier manipulation.

Here's a short example (not the complete solution;)

bool hasDoubleDigits( int phoneNumber )
{
 //convert int to string
 std::string phoneNumberSring;
 // iterate over string
 for( unsigned i=0; i!=phoneNumberString.size()-1;++i )
 {
   //check if phoneNumberString.at(i) == phoneNumberString.at(i+1)
   //return true
 }
// no doubledigits found, return false
}
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: