Function needed

i wrote this code that takes members info ( name , company , mobile ) and sorts
this info.

i need function to do this task

Mobile starts by
010 be 0100
016 be 0106
012 be 0122
018 be 0128

ex: if i entered 010 1234567 .... the number be 0100 123456789 .

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  #include<iostream>
#include<string.h>

using namespace std;

struct mobile
{
    char name[20];
    char combany[20];
    string number;

} member[2];

enum SortBy { number , Name};
void Entermobile(mobile arr[],int n);
void BubbleSort(mobile arr[],int n, SortBy sortby);
void Printmobile(mobile arr[],int n);

int main()
{
    int n=2,x;
    Entermobile(member, n);



    cout<<"\n\nSortingby Name:\n";
    BubbleSort(member,n,Name);
    cout<<"\nmobileSorted by Name:\n";
    Printmobile(member,n);
    cout<<"\n\nSortingby number:\n";
    BubbleSort(member,n,number);
    cout<<"\nmopileSorted by number:\n";
    Printmobile(member,n);
}

void Entermobile(mobile arr[],int n)
{
    for(int i=0; i<n; i++)
    {
        cout <<"\n Entering member "<<i+1<<endl;
        cout <<"\n Enter member Name : ";
        cin >>arr[i].name;
        cout<<"\n Enter member combany : ";
        cin>>arr[i].combany;
        cout<<"\n Enter member number : ";
        cin>>arr[i].number;
    }
}
void Printmobile(mobile arr[],int n)
{
    for(int i=0; i< n; i++)
        cout<<endl<<arr[i].name <<"\t"<< arr[i].combany << "\t" << arr[i].number ;
}
void BubbleSort(mobile arr[],int n, SortBy sortby)
{
    mobile temp;
    for(int i=1; i< n; i++)
        for(int j=0; j< n-i; j++)
        {
            if (
                sortby== Name && strcmp(arr[j].name,arr[j+1].name)>0 ||
                sortby== number && arr[j].number>arr[j+1].number )
            {
                temp = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = temp;
            }
        }
}
Any Help ....
The string class has some useful functions:
- find - search for a substring, say 010. Check if the return position is 0 (the phone number starts with 010). You don't care if it finds it anywhere else, like 111 010 2222
- replace - you can replace the first three characters with a new substring, 0100 for example
You can find very good documentation and examples on this site.
Now all you need is to put it together in a for loop, iterating over all prefixes you want to change
don't understand >>> Give me an example or edit my code ...

just to know how
Hey Guys ... need help here
!!!!
Topic archived. No new replies allowed.