Skip to main content

OOP

6.Problem statement

Develop an object oriented program in C++ to create a database of student  information system containing the following information: Name, Roll number, Class, division, Date of Birth, Blood group, Contact address, telephone number, driving license no. etc Construct the database with suitable member functions for initializing and destroying the data viz constructor, default constructor, Copy constructor, destructor, static member functions, friend class, this pointer, inline code and dynamic memory allocation operators-new and delete.

Program

#include<iostream>
#include<stdio.h>
#include<cstring>
using namespace std;
class personal;
static int count;
class person
{
      char *name;
      int *rollno,*classno;
      char *bloodgroup,*div;
     
     
      public:person()
             {
                    name=new char[20];
                    rollno=new int;
                    classno=new int;
                    bloodgroup = new char[3];
                    div=new char;
                   
             }
             ~person()
                {
                          cout<<"Destructor called ";
                 }
               
                   
           
           
      friend class personal;
     
           
 };


 class personal
 {
        char *address;
        long int *telephone;
        char *dob;
        public:personal()
               {
                  address=new char[50];
                  telephone = new long int;
                  dob= new char[10];
                }
                ~personal()
                {
                          cout<<"Destructor called ";
                 }
               
                void getdata(person &);
                void putdata(person &);
                int search (person *obj[]);
               
  };
  void personal::getdata(person &obj)
  {
           
        cout<<"--------ENTER INFORMATION----------"<<endl;
        cin.ignore();
        cout<<"Enter name :";
        cin.getline(obj.name,20);
        cout<<"Enter roll no :";
        cin>>*obj.rollno;
        cout<<"Enter class :";
        cin>>*obj.classno;
        cout<<"Enter div :";
        cin>>*obj.div;
        cin.ignore();
        cout<<"Enter blood group :";
        cin.getline(obj.bloodgroup,3);
       
            cout<<"Enter address :";
            cin.getline(this->address,50);
            cout<<"Enter telephone no :";
            cin>>*this->telephone;
            cin.ignore();
            cout<<"Enter date of birth :";
            cin.getline(this->dob,10);
   }
  void personal::putdata(person &obj)
   {
           cout<<"---------STUDENT INFORMAION-----------"<<endl;
           cout<<"Name is :"<<(char *)obj.name<<endl;
           cout<<"Roll no is :"<<*obj.rollno<<endl;
           cout<<"Class is :"<<*obj.classno<<endl;
           cout<<"Division is :"<<*obj.div<<endl;
           cout<<"Blood group is :"<<(char *)obj.bloodgroup<<endl;
           cout<<"Date of birth is :"<<(char *)this->dob<<endl;
           cout<<"Address is :"<<(char *)this->address<<endl;
           cout<<"Telephone number is :"<<*this->telephone<<endl;
         
   }
   int personal::search(person *obj[])
   {
       
       
         char temp[30];
         cout<<"Enter name :";
         cin.ignore();
         cin.getline(temp,30);
         for(int i=0;i<count;i++)
         {
                 if(strcmp(temp,(char *)obj[i]->name)==0)
                 {
                          return i;
                 }
          }
          return -1;
         
       
   }       
   int main()
   {
           personal *obj1[10];
           person *obj2[10];
           count = 0;
           char c='y';
           int choice,p;
           while(c=='y')
           {
               cout<<"Enter choice \n[1]Add data\n[2]Display data\n[3]Search\n[4]Delete\n";
               cin>>choice;         
               switch(choice)
               {
                    case 1:obj1[count]=new personal;
                           obj2[count]=new person;
                           obj1[count]->getdata(*obj2[count]);
                           count++;
                           break;
                    case 2:for(int i=0;i<count;i++)
                           {
                              obj1[i]->putdata(*obj2[i]);
                              cout<<endl;
                           }
                           break;
                    case 3:p=obj1[0]->search(obj2);
                           if(p==-1)
                           {
                               cout<<"not found"<<endl;
                            }
                            else
                            {
                                 cout<<"found"<<endl;
                                 obj1[p]->putdata(*obj2[p]);
                            }
                            break;
                    case 4:p=obj1[0]->search(obj2);
                           if(p==-1)
                           {
                               cout<<"not found"<<endl;
                            }
                            else
                            {
                                 cout<<"Found "<<endl;
                                 //obj1[p]->putdata(*obj2[p]);
                                 cout<<"Preparing to delete"<<endl;
                                 *obj1[p]=*obj1[count-1];
                                 *obj2[p]=*obj2[count-1];
                                 obj1[p]->putdata(*obj2[p]);
                                // cout<<endl<<obj1[count-1]<<endl;
                                 delete obj1[count-1];
                                 delete obj2[count-1];
                               
                                 count--;
                               
                               
                            }
                            break;
                    default:cout<<"Invalid choice ";
                            break;
                           
                           
                }
                cout<<"Do you want to continue :";
                cin>>c;
           }
   
       
       
           
         
           return 0;
}

Comments

Popular posts from this blog

DSL

9: Program Setatement A palindrome is a string of character that‘s the same forward and backward. Typically, punctuation, capitalization, and spaces are ignored. For example, ‖Poor Dan is in a droop‖ is a palindrome, as can be seen by examining the characters ―poor danisina droop‖ and observing that they are the same forward and backward. One way to check for a palindrome is to reverse the characters in the string and then compare with them the original-in a palindrome, the sequence will be identical. Write C++ program with functions- 1. to check whether given string is palindrome or not that uses a stack to determine whether a string is a palindrome. 2. to remove spaces and punctuation in string, convert all the Characters to lowercase, and then call above Palindrome checking function to check for a palindrome 3. to print string in reverse order using stack Program: #include<iostream> #include<string.h> #define MAX 100 using namespace std;  struct stack ...

OOP

21.Problem statement  Write C++ program using STL for implementation of stack & queue using SLL Program #include<iostream> #include<stack> #include<stdlib.h> using namespace std; void display(stack<int>s) { cout<<"\nElement in stack are:- "; while(!s.empty()) { cout<<s.top()<<"  "; s.pop(); } } int main() { stack<int>s; int choice,t; int x; while(1) { cout<<"\n\n*********************************"; cout<<"\n        STACK USING STL"; cout<<"\n*********************************"; cout<<"\n\n1.Push data"; cout<<"\n2.Pop data"; cout<<"\n3.Size of stack"; cout<<"\n4.First Element"; cout<<"\n5.Display Element in stack"; cout<<"\n6.Exit"; cout<<"\nEnter Your choice:- "; cin>>choice;...