Show student Information using Structure in C++


This program defines a student struct that has three members: name, rollno, and age. It then creates an instance of this struct: s. The program prompts the user to enter values for name, rollno, and age using cout statements and cin input. The cin.getline() function is used to read in the name member as a string with a maximum length of 30 characters.

The program then prints the values of each member of s using cout statements. Overall, this program is an example of how to define and use a struct in C++ to store information about a student. It creates an instance of the student struct, prompts the user to enter values for its members, and then prints out the values of each member.

Source Code

#include<iostream>
using namespace std;
struct student
{
  char name[30];
  int rollno;
  int age;
};
int main()
{
  student s;
  cout<<"\nEnter Student Name: ";
  cin.getline(s.name, 30);
  cout<<"\nEnter Student Roll No: ";
  cin>>s.rollno;
  cout<<"\nEnter Student Age: ";
  cin>>s.age;
  cout<<"\nStudent Record:"<<endl;
  cout<<"\nName: "<<s.name<<endl;
  cout<<"\nRoll No: "<<s.rollno<<endl;
  cout<<"\nAge: "<<s.age;
  return 0;
}
To download raw file Click Here

Output

Enter Student Name: Ram
Enter Student Roll No: CS1201
Enter Student Age: 19
Student Record:

Name: Ram
Roll No: CS1201
Age: 19

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples