Store Student Detail using Function in C++

Here we will Store Student Detail using Function in C++, Program will Sore Student detail like roll-number, age and name

We have used two user Defined Functions in the program.

In this, the function void get_data() will stores the details from the user while the void put_data() will print that detail.

In a way, we can say that the function void get_data() will act as input and function void put_data() will act as output.

Here is a Diagram,

store-student-detail-using-function-in-cpp

Here is the program,

#include<iostream.h>
#include<coio.h>
#include<stdio.h>// for gets() function

// data member declare in globally
 int roll,age;
 char name[10];

// function member declaration
 void get_data();
 void put_data();

 void main(void)
  {
     clrscr();

     getdata(); // for input
     putdata();  // for output

     getch();
  }

 void get_data()
  {
     cout<<"\nEnter roll no: "; cin>>roll;
     cout<<"Enter age : "; cin>>age;
     cout<<"Enter Name : ";
     gets(name);
  }

 void put_data()
  {
    cout<<"\nDisplay Record";
    cout<<"\nRoll no : "<<roll;
    cout<<"\nStu. age: "<<age;
    cout<<"\nStu.Name: "<<name;
  }
OUTPUT:-
Enter roll no: 101
Enter age : 25
Enter Name : Rohit sherma

Display Record
Roll no : 101
Stu. age: 25
Stu.Name: Rohit sherma

Explanation:-

In the Program inside the main() function getdata() and putdata() are declared while their definition is outside the main()

getdata() function will take the record from the user and store them while putdata function will display them into monitor, you can see in the above diagram.

Read also:

store student detail using function with structure in C++