The perfect place for easy learning...

OOPs using C++

×

List of Programs


C++ Practical Programs


Aim


Write a C++ program to declare Struct. Initialize and display contents of member variables.

Procedure


  • Step 1 - Include the required header files (iostream.h and conio.h).
  • Step 2 - Create a structure (college_info) with the following member variables.
    • college_name, college_code, dept, and intake as data members.
  • Step 3 - Create a main() method.
  • Step 4 - Create a variable of the above structure inside the main() method.
  • Step 5 - Then, read data into member variables of that structure using structure variable with dot operator.
  • Step 6 - Finally, display data of member variables of that structure using structure variable with dot operator.

Implementation


C++ Program
#include <iostream>

using namespace std;

struct college_info{
    char college_name[15];
    char college_code[2];
    char dept[50];
    int intake;
};

int main()
{
    struct college_info college;
    
    cout<<"\n+++++ Enter the College Information +++++\n\n";
    cout<<"Name of the college: ";
    cin>>college.college_name;
    cout<<"College Code: ";
    cin>>college.college_code;
    cout<<"Department: ";
    cin>>college.dept;
    cout<<"Department In-take: ";
    cin>>college.intake;

    cout<<"\n\n********* College Information *********\n\n";
    cout<<"Name of the college : "<<college.college_name;
    cout<<"\nCollege University Code: "<<college.college_code;
    cout<<"\nName of the Department: "<<college.dept;
    cout<<"\nThe department of "<<college.dept<<" has in-take : "<<college.intake;
    cout<<"\n\n-----------------------------------------\n\n";
    
    return 0;
}

Result



Place your ad here
Place your ad here