Department of Computer Engineering has student's club named 'Pinnacle Club'. Students of Second, third and final year of department can be granted membership on request. Similarly one may cancel the membership of club. First node is reserved for president of club and last node is reserved for secretary of club. Write C++ program to maintain club member‘s information using singly linked list. Store student PRN and Name. Write functions to a)Add and delete the members as well as president or even secretary. b)Compute total number of members of club c)Display members d)Display list in reverse order using recursion e)Two linked lists exists for two divisions. Concatenate two lists.

Department of Computer Engineering has student's club named 'Pinnacle Club'. Students of
Second, third and final year of department can be granted membership on request.  Similarly one may cancel the membership of club. First node is reserved for president of club and last
node  is  reserved  for  secretary  of  club.  Write  C++  program  to  maintain  club  member‘s
information using singly linked list. Store student PRN and Name. Write functions to
a)Add and delete the members as well as president or even secretary.
b)Compute total number of members of club
c)Display members
d)Display list in reverse order using recursion
e)Two linked lists exists for two divisions. Concatenate two lists.

#include<iostream>
OUTPUT FOR THE PROGRAM
#include<string.h>
using namespace std;

struct Node
{
   int Roll;
   char Name[10];
   struct Node *Next;
}*head,*head2;

void create_SLL()
{
    int i, nodes; 
    struct Node *temp, *prev;
 
    head = NULL;
 
    cout<<"\n\n How many nodes: ";
    cin>>nodes;
 
    for(i=0; i<nodes; i++)
    {
       temp = new(struct Node); //Step 1: Allocate Memory
 
       cout<<"\n\t Enter Roll No: "; //Step 2: Store data and address
       cin>>temp->Roll;
 
       cout<<"\n\t Enter Name: ";
       cin>>temp->Name;
 
       temp->Next = NULL;
 
       if(head == NULL) //Step 3: Attach node in linked List
       {
          head = temp;
          prev = head;
       }
       else
       {
          prev->Next = temp;
          prev = prev->Next;
       }
 
    } 
 
}

void display_SLL()
{
    struct Node *p;
 
    p = head;
    cout<<"\n\n Head";
    while(p != NULL)
    {
       cout<<"---->|"<<p->Roll<<"|"<<p->Name<<"|";
       p = p->Next;
    }
    cout<<" ---->NULL";

}

void count_mem()
{
int cnt = 0;
struct Node *p;
p = head;
while(p!=NULL)
{
cnt ++;
p=p->Next;
}
cout<<"\n No of members : "<<cnt;
}

void rev_SLL()
{
struct Node *p, *temp;

p = head;
head2 = NULL;

while(p != NULL)
{
temp = new(struct Node);

temp->Roll=p->Roll;
strcpy(temp->Name,p->Name);
temp->Next = NULL;

if(head2==NULL)
head2=temp;
else
{
temp->Next = head2;
head2 = temp;
}
p=p->Next;
}

p=head2;
cout<<"\n\n Head";
    while(p != NULL)
    {
       cout<<"---->|"<<p->Roll<<"|"<<p->Name<<"|";
       p = p->Next;
    }
    cout<<" ---->NULL";

}

void join_SLL()
{
struct Node *p;
p = head;
while(p->Next!=NULL)
p = p->Next;
p->Next = head2;
display_SLL();
}

void delete_SLL()
{
struct Node *p, *q;
int rno;

cout<<"Enter roll no. to delete";
cin>>rno;

p = q = head;
while(p != NULL)
{
   if(p->Roll == rno)
   {
     if(p == head)
     {
        head = head->Next;
        delete p;
     }  
     else
     {
        q->Next = p->Next;
    delete p;
             }
     break;   
   }
   else
   {
      q = p;
      p = p->Next;
   }
}
if(p == NULL)  
    cout<<"\n\n\t Not Found.....!!!";

}

int main()
{

    cout<<"\n\n ---------*** Operations on Single Linked List ***---------";
 
    cout<<"\n\n ---------1. Create SLL";
    create_SLL();
 
    cout<<"\n\n ---------2. Display SLL"; 
    display_SLL();
 
     cout<<"\n\n ---------3. Count SLL";
    count_mem();
 
    cout<<"\n\n ---------4. Delete SLL";
    delete_SLL();
    display_SLL();
    cout<<"\n\n";
 
     cout<<"\n\n ---------5. Reverse SLL";
    rev_SLL();
 
     cout<<"\n\n ---------6. Join SLL";
    join_SLL();
    cout<<"\n\n";
 
    return 0;
}


For more such posts click the link:-http://svencrai.com/G8W

Comments

Popular posts from this blog

A book shop maintains the inventory of books that are being sold at the shop. The list includes details such as author, title, price, publisher and stock position. Whenever a customer wants a book, the sales person inputs the title and author and the system searches the list and displays whether it is available or not. If it is not, an appropriate message is displayed. If it is, then the system displays the book details and requests for the number of copies required. If the requested copies book details and requests for the number of copies required. If the requested copies are available, the total cost of the requested copies is displayed; otherwise the message ?Required copies not in stock? is displayed. Design a system using a class called books with suitable member functions and Constructors. Use new operator in constructors to allocate memory space required. Implement C++ program for the system

Write C++ program for storing appointment schedule for day. Appointments are booked randomly using linked list. Set start and end time and min and max duration for visit slot. Write functions for- a)Display free slots b)Book appointment c)Cancel appointment ( check validity, time bounds, availability etc) d)Sort list based on time e)Sort list based on time using pointer manipulation

Imagine a publishing company which does marketing for book and audiocassette versions. Create a class publication that stores the title (a string) and price (type float) of a publication. From this class derive two classes: book, which adds a page count (type int), and tape, which adds a playing time in minutes (type float). Write a program that instantiates the book and tape classes, allows user to enter data and displays the data members.