c++ array problem input and sub menus, assignment is due really soon

Pages: 123
@seeplus has pretty much done it for you, but it may be beyond a beginner. If you don't understand it, you should ask.

std::getline will read a whole line, then you can do stuff with the string it returns. But for numbers, you could just use std::cin >> phoneno, then check if the number is too large.
Last edited on
@kbw
Tried to follow your advice but still cant figure out how even when i tried which takes me so long, sorry for timing reasons

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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <iostream>   
#include <string>   
using namespace std;
using std::getline;


class Record 
{
private:
    std::string en;
    std::string em;
    int pn;

public:
    std::string getName() const { return en; }
    std::string getEmailAddress() const { return em; }
    int getPhoneNo() const{ return pn; }
    void setName(std::string value) { en = value; }
    void setEmailAddress(std::string value) { em = value; }
    void setPhoneNo(int value) { pn = value; }
    void addRecord(Record rec) 
    {
        if (lastRecord < MaxRecords) 
        {
            records[lastRecord] = rec;
            ++lastRecord;
        }
    }
    int MaxRecords = 20;
    int records[];
    int lastRecord = 0;

};



int main(int argc, char* argv[])

{
    int e = 1;
    int sbr = 1;
    int e2 = 1;

    while (e != 5)
    {
        cout << "*******MAIN MENU******\n";
        cout << "1. Initialize the address book\n";
        cout << "5. Quit\n";
        cout << "please enter 1, 2, 3, 4, 5";
        constexpr int MaxRecords = 20;
        Record records[MaxRecords];
        int lastRecord = 0;
        cin >> e;
    
            switch (e)
            {
               while (e != 4)
               case 1:
                {
                    cout << "Name is : Larwarnce cheung \n";
                    cout << "Email is : enccl@eie.polyu.edu.hk \n";
                    cout << "telephone is : 27666131 \n";
                    cout << "Name is : Helen Wong \n";
                    cout << "Email is : helenwong@yahoo.com \n";
                    cout << "telephone is : 94665888\n";
                    cout << "Name is : Simon Sui \n";
                    cout << "Email is : ss123@gmail.com \n";
                    cout << "telephone is : 64441234\n";
                    cout << "Name is : Mary Ho \n";
                    cout << "Email is : ho.mary1@@navigator.com \n";
                    cout << "telephone is : 21111112\n";
                    cout << "Initializting is completed\n" << endl;
                    break;
                }
               case 2:
               {
                   for (int i = 0; i < selection; ++i) 
                   {
                       Record record = readNewRecord();
                       addRecord(record);
                       Record readNewRecord() {
                           Record record;
                           std::cin >> record.name;
                           std::cin >> record.email;
                           std::cin >> record.phoneno;
                           return record;
                       }
                   }
             
               }
               case 3:
               {

               }
               case 4:
               {

               }
               case 5:
               {

               }
               default:
               {
                   cout << "Error try again" << endl;
                   break;
               }
            }
    }
    return 0;
}
Last edited on
Topic archived. No new replies allowed.
Pages: 123