Social Icons

banner image

EXAMPLES ON SRUCTURE IN C++

ENUMRATION
#include<iostream.h>
#include<conio.h>
enum Days {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};
main()
{
      enum Days Today = Sunday;
      switch(Today)
      {
                   case 0:
                         cout<<"its sunday";
                         break;
                   case 1:
                         cout<<"its monday";
                         break;
                         default:
                                 cout<<"not monday";
                                 }
                                 getch();
                                 }
UNION
#include<iostream.h>
#include<conio.h>
main()
{
struct stu1
      {
     
    //  int roll;
      float marks;
      char name[20];
      }d1 ;
     

union abc
      {
     
 //  int roll;
    float marks;
      char name[20];
      }d ;
     
      

 //  cout<<"enter the roll number";
//  cin>>d1.roll;
     cout<<"enter ur marks";
     cin>>d1.marks;
     cout<<"enter name";
     cin>>d1.name;
      cout<<endl; 

//  cout<<"enter the roll number";
//  cin>>d.roll;
     cout<<"enter ur marks";
     cin>>d.marks;
      cout<<"enter name";
     cin>>d.name;
     cout<<endl;
     cout<<"sizeof(d1)is"<<sizeof(d1);
      cout<<"\n";
      cout<<"sizeof(d)is"<<sizeof(d);
      getch();
      }
//*Function returning a Structure */
    #include <iostream.h>
    #include <conio.h>
    struct student
    {
        int student_roll_no ;
        int marks_in_subject1 ;
        int marks_in_subject2 ;
    } ;
     main ()
    {
        struct student function ()  ;
        struct student t ;
        float result ;
       
        t = function () ;
    cout<<"Student Record : \n";
    cout<<"Roll Number    : "<<t.student_roll_no;
    cout<<"Subject 1 marks  : "<< t.marks_in_subject1 ;
    cout<<"Subject 2 marks : "<< t.marks_in_subject2 ;
    getch () ;
    }
    struct student function ( )
    {
        struct student s1 = { 3032, 89, 78 } ;
        return ( s1 ) ;
    }

ASSIGNMENT AND POINTER
#include<iostream.h>
#include<conio.h>
main()
{
      struct abc
      {
      int roll;
      float marks;
      };
      abc d,d1;
       abc* d2;
d2=&d;
  cout<<"enter the roll number";
  cin>>d.roll;
     cout<<"enter ur marks";
     cin>>d.marks;
    // d1=d;
     cout<<d2<<endl;
   
    cout<<d2->roll<<"      "<<d2->marks;
      getch();
      }

 STRUCTURE WITH ARRAY
#include<iostream.h>
#include<conio.h>
main()
{
      struct abc
      {
             int roll[10];
             float marks[10];
             }d;
            
             for(int i=0;i<10;i++)
             {
                     cout<<"enter the oll number";
                     cin>>d.roll[i];
                     cout<<"enter the marks";
                     cin>>d.marks[i];
                     }
                     for(int i=0;i<10;i++)
             {
                     cout<<d.roll[i]<<" "<<d.marks[i]<<"\n";
                     }
                     getch();
                     }
EXAMPLES ON SRUCTURE IN C++ EXAMPLES ON SRUCTURE IN C++ Reviewed by Shobhit Goel on August 17, 2015 Rating: 5

No comments:

Airtel Hackaton 2017

Powered by Blogger.