Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Question: Create a Linked list of nodes. Each node should have student names,age,course num,grades and pointer that is used to link the next node in the list. Use appendnode member function to generate linked list of 5 students. Create a search member function to display the name of student who has got 'A' grade . Assume that only one student got "A" grade.

I am new to linked list and nodes, so I am not too sure if what I am doing is correct. Any help would be appreciated.

What I have tried:

C++
#include <iostream>
#include <cstring>
using namespace std;

struct node
{
    char name;
    char age;
    char coursenum;
    char grade;
    node *next;
};

node* search(node* head)
{
    node *temp=head;
    while (temp!=NULL)
    {
        if(strcmp(head->grade, grade)=="A")
        {
            cout << name;
            return name;
        }
        temp = temp-> next;
    }
    
}

int main()
{
    node *head = NULL;
    
    char name;
    char age;
    char coursenum;
    char grade;
    
    int i=0;
    
    while (i<5)
    {
        cout << "Enter the students name: ";
        cin >> name;
        cout << "Enter the studens age: ";
        cin >> age;
        cout << "Enther the students course number: ";
        cin >> coursenum;
        cout<< "Enter the students grade: ";
        cin >> grade;
        node *temp = new node;
        temp->grade = grade;
        temp-> next = head;
        head = temp;
        i++;
    }
    search(head);
}
Posted
Comments
Richard MacCutchan 11-Nov-17 8:57am    
Why have you tagged this question node.js when it is clearly C++ code? And a Google search will find you many samples of linked lists.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900