store student records 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,

Here is the program,

#include<iostream>
#include<stdio>// for gets() function
using namespace std;

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

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

 int main()
  {

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

return 0;  }

 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

C++ Examples

Like it?

2 thoughts on “store student records using function in c++”

  1. #include
    #include// for gets() function
    using namespace std;

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

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

    int main()
    {

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

    return 0; }

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

    void put_data()
    {
    cout<<"\nDisplay Record";
    cout<<"\nRoll no : "<<roll;
    cout<<"\nStu. age: "<<age;
    cout<<"\nStu.Name: "<<name;
    }
    [Error] 'getdata' was not declared in this scope in your

    1. try this..

      /******************************************************************************

      Online C++ Compiler.
      Code, Compile, Run and Debug C++ program online.
      Write your code in this editor and press “Run” button to compile and execute it.

      *******************************************************************************/

      #include
      #include// for gets() function
      using namespace std;

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

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

      int main()
      {

      get_data(); // for input
      put_data(); // for output

      return 0;

      }

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

Average
5 Based On 1

Leave a Reply

Your email address will not be published.