define linked list called student
name number address
and the following function
add function that add the information of the student
2
search function that search print the name of all student with some address search ("zarqa,amman,irbid") will print the name of students lives in amman
3
count function that return the number of students that lives address
count ("amman ") will return the number of student lived in amman

please help me

Recommended Answers

What kind of help do you need?

Jump to Post

All 4 Replies

What kind of help do you need?

i want solution this program because I am tired of this question

Well, in that case, you have come to the wrong place; no one here is going to do your homework for you. We will give advice, help and comiseration, but we won't help you cheat.

thanx

#include <iostream>

using namespace std;


struct student{
    int number;
    char* name;
    char* address;
    student* next;
};

void add(student* & students, student s){
    student* temp;
    temp = students;
    if(students == NULL)
    {
        students = new student;
        students->number = s.number;
        students->name = s.name;
        students->address = s.address;
        students->next = NULL;
        return;
    }
    while (temp->next != NULL)
    {
        temp = temp->next;
    }
    temp->next = new student;
    temp->next->number = s.number;
    temp->next->name = s.name;
    temp->next->address = s.address;
    temp->next->next = NULL;
}

void print(student* std)
{
    cout<<"name"<<"\t"<<"number"<<"\t"<<"address"<<"\n";
    cout<<"----"<<"\t"<<"------"<<"\t"<<"-------"<<"\n";
    student* temp = std;
    while(temp != NULL)
    {
        cout<<temp->name<<"\t"<<temp->number<<"\t"<<temp->address<<"\n";
        temp = temp->next;
    }
}

void search(student* std, char* address)
{
    cout<<"the name of students lived in "<<address<<" are:\n";
    student* temp = std;
    while(temp != NULL)
    {
        if(temp->address == address)
            cout<<temp->name<<"\n";
        temp = temp->next;
    }
}

void count(student* std, char* address)
{
    cout<<"the number of students lived in "<<address<<" is = ";
    student* temp = std;
    int counter = 0;
    while(temp != NULL)
    {
        if(temp->address == address)
            counter++;
        temp = temp->next;
    }
    cout<<counter<<"\n";
}

void main()
{
    student* std;
    std = NULL;
    student s;
    s.number = 1;
    s.name = "Sdam";
    s.address = "Irbid";
    s.next = NULL;

    add(std, s);

    s.number = 2;
    s.name = "Hani";
    s.address = "Amman";
    s.next = NULL;

    add(std, s);

    s.number = 3;
    s.name = "Sawsan";
    s.address = "Irbid";
    s.next = NULL;

    add(std, s);

    s.number = 4;
    s.name = "Ahmad";
    s.address = "Zarqa";
    s.next = NULL;

    add(std, s);

    s.number = 5;
    s.name = "Omar";
    s.address = "Amman";
    s.next = NULL;


    add(std, s);

    print(std);

    cout<<"---------------------------------------------------------------"<<endl;

    search(std, "Irbid");

    cout<<"---------------------------------------------------------------"<<endl;

    count(std, "Amman");

    cout<<"---------------------------------------------------------------"<<endl;


    system("pause");

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.