-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.c
More file actions
63 lines (51 loc) · 1.63 KB
/
code.c
File metadata and controls
63 lines (51 loc) · 1.63 KB
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
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Phone {
private:
string stdCode;
string exchangeCode;
string phoneNumber;
public:
Phone(string stdCode, string exchangeCode, string phoneNumber) {
this->stdCode = stdCode;
this->exchangeCode = exchangeCode;
this->phoneNumber = phoneNumber;
}
void modifyPhoneNumber() {
// Add 1 to 1st digit of STD code
if (stdCode[0] == '9')
stdCode[0] = '1';
else
stdCode[0] += 1;
// Reverse the first two digits in the phone number
phoneNumber[0] = stdCode[0];
phoneNumber[1] = stdCode[1];
// Display the modified phone number
cout << stdCode << "-" << exchangeCode << "-" << phoneNumber << endl;
}
};
int main() {
vector<Phone> phones;
int n;
cout << "Enter the number of phone numbers to modify (max 10): ";
cin >> n;
if (n > 10) {
cout << "Number of phone numbers exceeds limit." << endl;
return 1;
}
for (int i = 0; i < n; i++) {
string stdCode, exchangeCode, phoneNumber;
cout << "Enter STD code, Exchange code, and Phone number for phone " << i + 1 << ": ";
cin >> stdCode >> exchangeCode >> phoneNumber;
Phone phone(stdCode, exchangeCode, phoneNumber);
phones.push_back(phone);
}
cout << "Modified phone numbers:" << endl;
for (int i = 0; i < n; i++) {
cout << "Modified phone number for phone " << i + 1 << ": ";
phones[i].modifyPhoneNumber();
}
return 0;
}