class

what is the syntax for a search in turbo c++ using a class?
I'm unsure what you are talking about. What search? C++ is not SQL. C++ is not a searching language, so what you request confuses the hell out of me.
closed account (o3hC5Di1)
Hi there,

Taking my post in your other thread into account, it woul be something along the lines of:

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
struct PhoneNumber
{
    std::string number;
    std::string name;
};

class PhoneBook
{
    Phonenumber listing[MAX_PN];
    unsigned int count;

    public:
        void add(PhoneNumber pn);
        void delete(int index);
        void edit(int index);
        void search(std::string search_string);
};

int PhoneBook::search(std::string search_string)
{
    for (int i = 0 ; i< MAX_PN; i++)
    {
        //pseudocode
        if  search_string is find in either number or name then return the index number
    }

    //pseudocode
    if nothing found return negative number
}


int main ()
{
    PhoneNumber p1 = { "123456", "some name"};
    PhoneNumber p2 = { "123789", "some other name"};

    PhoneBook book;
    book.add(p1);
    book.add(p2);

    int s;
    s = book.search("123456");
    
    //pseudocode
    if s >= 0, print out data, otherwise print "nothing found"
    return 0;
}


To be safe there should go some array boundary checking in there.

Hope that helps.

All the best,
NwN
Last edited on
Topic archived. No new replies allowed.