Skip to main content

DSL C19

 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) Two linked lists exists for two divisions. Concatenate two lists.


 #include<iostream>  
   
 using namespace std;  
   
 struct node{  
        
      int PRN;  
      char Name[10];  
      node *next;  
 };  
   
 node *nnode,*npre;  
 char ch;  
 int prn,total=0,choice;  
   
 class PinClub{  
        
      public:  
             
           node *President,*Secretary;  
             
           PinClub(){  
             
           President=Secretary=NULL;  
      }  
        
      void create();  
      void display();  
      void newpresident();  
      void DelPre();  
      void DelSec();  
      void DelMem();  
      void Total();  
 };  
   
 void PinClub::create()  
 {  
      do{  
           nnode=new node;  
           nnode->next=NULL;  
           cout<<"Enter PRN NO. of Student : "<<endl;  
           cin>>nnode->PRN;  
           cout<<"Enter Name of Student : "<<endl;  
           cin>>nnode->Name;  
             
           if (President==NULL || Secretary==NULL)  
           {  
           President=Secretary=nnode;  
           }  
           else  
           {  
           Secretary->next=nnode;  
           Secretary=nnode;  
           }  
           cout<<"Do you want to Add more Students to Club (y or n) ";  
           cin>>ch;  
      }while(ch=='y');       
 }  
   
   
 void PinClub::display()  
 {    
   cout<<"<><><><><> List of Members in Club <><><><><>"<<endl;  
   cout<<"PRN NO."<<" "<<"Name"<<endl;  
   node *temp;  
   temp=President;  
   while(temp!=NULL)  
      {  
      cout<<" "<<temp->PRN<<"   ";  
      cout<<temp->Name<<endl;  
      temp=temp->next;  
  }  
 }  
   
 void PinClub::newpresident()  
 {   
   npre=new node;  
   npre->next=NULL;  
   cout<<"Enter PRN NO. of New President : "<<endl;  
   cin>>npre->PRN;  
   cout<<"Enter Name of New President : "<<endl;  
   cin>>npre->Name;  
   npre->next=President;  
   President=npre;  
   cout<<"Name of New President : "<<President->Name<<endl;  
   cout<<"PRN NO. of New President : "<<President->PRN<<endl;  
 }  
   
 void PinClub::DelPre()  
 {  
      node *temp;  
      temp=President;  
      President=President->next;  
      delete temp;  
      cout<<"Name of New President : "<<President->Name<<endl;  
      cout<<"PRN NO. of New President : "<<President->PRN<<endl;  
 }  
   
 void PinClub::DelSec()  
 {  
      node *temp;  
      temp=President;  
      while(temp->next!=Secretary){  
      temp=temp->next;  
      }  
   Secretary=temp;  
   delete temp->next;  
   cout<<"Name of New Secretary : "<<Secretary->Name<<endl;  
   cout<<"PRN NO. of New Secretary : "<<Secretary->PRN<<endl;  
 }  
   
 void PinClub::DelMem()  
 {  
      cout<<"Enter PRN no. Member to be deleted"<<endl;  
      cin>>prn;  
      node *temp,*temp1;  
      temp=President;  
      while((temp->next)->PRN!=prn){  
      temp=temp->next;  
      }  
      temp1=temp->next;  
      temp->next=temp1->next;  
       delete temp1;  
 }  
   
 void PinClub::Total()  
 {  
   node *temp;  
   temp=President;  
   while(temp!=NULL)  
      {  
           total=total+1;  
           temp=temp->next;       
      }  
      cout<<"Total No. of Elements Are :"<<total<<endl;  
 }  
   
   
 int main(){  
        
      PinClub M1,M2;  
      M1.create();  
      M1.display();  
        
      cout<<"\nPresident Name : "<<M1.President->Name<<endl;  
      cout<<"Secretary Name : "<<M1.Secretary->Name<<endl;  
        
   do  
      {  
   cout<<"\n1.Insert New President\n2.Delete President\n3.Delete Secretary\n4.Delete Member\n5.Display\n6.Find total No. of members\n7.Concatenate two list\n0. Exit";  
   cout<<"\nEnter your choice: ";  
   cin>>choice;  
   switch(choice)  
           {  
                case 0:   
                     break;   
                case 1:   
                  M1.newpresident();  
                     break;  
                case 2:       
                  M1.DelPre();  
                     break;  
                case 3:   
                  M1.DelSec();  
                     break;  
                case 4:   
                  M1.DelMem();  
                     break;  
                case 5:   
                  M1.display();  
                  break;  
                case 6:  
                     M1.Total();  
                     break;  
                case 7:  
                     cout<<"Enter the Details of new Club"<<endl;  
                     M2.create();  
                     M2.display();  
                     M1.Secretary->next=M2.President;  
                     M1.Secretary=M2.Secretary;  
                     M1.display();  
                     break;  
                default:  
                     cout<<"Wrong choice";  
           }  
      }while(choice!=0);  
      return 0;  
 }  

Comments

Popular posts from this blog

DSL A1

Hello Friends lets See the first practical of Data Structure Laboratory(DSL) of SPPU Second Year. Some of the students are afraid of coding as it is new to all of us. So we are here to conquer your fear. You will find it easy as it explained by students only. So lets Get into it The first practical of part A is : In second year computer engineering class, group A student’s play cricket, group B students play badminton and group C students play football. Write a Python program using functions to compute following: -  a) List of students who play both cricket and badminton  b) List of students who play either cricket or badminton but not both  c) Number of students who play neither cricket nor badminton  d) Number of students who play cricket and football but not badminton.  (Note- While realizing the group, duplicate entries should be avoided, Do not use SET built-in functions)  So most of us know the SET theory in mathematics. The above problem is very easy if you have knowledge about

Bouncing Ball

Group B   Practical 4 a   Problem Statement :   Write a C++ program to implement bouncing ball using sine wave form. Apply the concept of polymorphism. Check Out Code Here  ðŸ‘‡ Outputs :  Code can get updated so also come back later to see if there is any changes. Also if there is any problem with code you can comment below. If you like it, do share with your friends.😊

OOP 6

   Object Oriented Programming Group B - Practical : 6 Problem Statement :  Write C++ program using STL for sorting and searching user defined records such as personal records (Name, DOB, Telephone number etc) using vector container. Check Out Code Here  ðŸ‘‡ Code can get updated so also come back later to see if there is any changes. Also if there is any problem with code you can comment below. If you like it, do share with your friends.😊