Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

C++ program to print students details using structure

YASH PAL, 31 July 202419 February 2026

In this post we will write a C++ program to print student details using structure. user will enter the detail of 4 students like his/her name, roll number, math, physics, and c++ subject marks, and then the program will print the details of the students including the Grades.

C++ program to print student details using structure

C++ program to print student details using structure.

#include<iostream>
#include<conio.h>
#include<windows.h>

BOOL gotoxy(const WORD x, const WORD y) {
    COORD xy;
    xy.X = x;
    xy.Y = y;
    return SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), xy);
}

struct res
{
    int rn;
    char name[30];
    int math;
    int phy;
    int c;
};
struct res a[5];

int main()
{
   system("cls");

    int i;
    int total;
    int avg;

    for(i=0;i<=4;i++)
    {
        std::cout<<"Name = ";
        std::cin>>a[i].name;

        std::cout<<"Roll Number = ";
        std::cin>>a[i].rn;

        std::cout<<"Math Number = ";
        std::cin>>a[i].math;

        std::cout<<"Physics Number = ";
        std::cin>>a[i].phy;

        std::cout<<"C++ Number = ";
        std::cin>>a[i].c;
    }

    for(i=0;i<=4;i++)
    {
        total = a[i].math+a[i].phy+a[i].c;
        avg = total/3.0;
        gotoxy(20,5+i);

        std::cout<<a[i].name<<std::endl;

        gotoxy(30,5+i);

        std::cout<<a[i].rn<<std::endl;
        gotoxy(37,5+i);

        std::cout<<a[i].math<<std::endl;
        gotoxy(44,5+i);

        std::cout<<a[i].phy<<std::endl;
        gotoxy(51,5+i);

        std::cout<<a[i].c<<std::endl;
        gotoxy(58,5+i);

        std::cout<<total<<std::endl;
        gotoxy(65,5+i);

        std::cout<<avg<<std::endl;

        if(avg >= 80)
        {
            gotoxy(73,5+i);
            std::cout<<"A"<<std::endl;
        }
        else if(avg >= 70 && avg <= 79)
        {
            gotoxy(73, 5+i);
            std::cout<<"B"<<std::endl;
        }
        else if(avg >= 60 && avg <= 69)
        {
            gotoxy(73,5+i);
            std::cout<<"C"<<std::endl;
        }
        else if(avg >= 50 && avg <= 59)
        {
            gotoxy(73,5+i);
            std::cout<<"C"<<std::endl;
        }
        else
        {
            gotoxy(73,5+i);
            std::cout<<"Fail"<<std::endl;
        }
    }

    gotoxy(20,4);
    std::cout<<"Name"<<std::endl;
    gotoxy(30,4);
    std::cout<<"Roll"<<std::endl;
    gotoxy(37,4);
    std::cout<<"Math"<<std::endl;
    gotoxy(44,4);
    std::cout<<"Phy"<<std::endl;
    gotoxy(51,4);
    std::cout<<"C++"<<std::endl;
    gotoxy(58,4);
    std::cout<<"Total"<<std::endl;
    gotoxy(65,4);
    std::cout<<"Aver"<<std::endl;
    gotoxy(73,4);
    std::cout<<"Grade"<<std::endl;

    getch();
    return 0;
}

Output

Name = yashpal
Roll Number = 5
Math Number = 50
Physics Number = 70
C++ Number = 80
Name = yash
Roll Number = 6
Math Number = 70
Physics Number = 90
C++ Number = 80
Name = rahul
Roll Number = 7
Math Number = 80
Physics Number = 80
C++ Number = 80
Name = pooja
Roll Number = 8
Math Number = 80
Physics Number = 90
C++ Number = 100
Name = Kajal
Roll Number = 9
Math Number = 70
Physics Number = 70
C++ Number = 70

Name     Roll    Math    Phy     C++     Total   Aver    Grade
yashpal  5       50      70      80      200     66      C
yash     6       70      90      80      240     80      A
rahul    7       80      80      80      240     80      A
pooja    8       80      90      100     270     90      A
kajal    9       70      70      70      210     70      B
C++ Programming Tutorials coding problems solutions C++ ProgramsPrograms

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

C++ Program to print a message on the screen
Project - Library Management System Program in C++
C++ Program to calculate the salary of the servant
C++ Program to find out the grades of given marks
C++ Program to find out the greater number from given numbers
C++ Program to find out whether the given number is odd or even
C++ Program to inherit derived constructor
C++ Program to display the reverse of a given number
C++ Program to print the ASCII value of a character
C++ Program to convert temperature from Fahrenheit to centigrade
C++ Program to enter two numbers and show their sum
C++ Program to swap two numbers using third variable
C++ Program to calculate the result of students using marks
C++ game to find out a number
C++ Program to print the table of a number
C++ Program to find out the smallest number from given numbers
C++ Program to calculate the factorial of a given number
C++ Program to select an operation from a list and display its results
C++ Program to generate a random number in circles and find out the sum
C++ Program to solve arithmetic operations
C++ Program to convert the dollar into different currencies
C++ Program to display the given number in roman number
C++ Program to find out whether the given character is a vowel or not
C++ Program to use symbols as words using preprocessor Directives
C++ Program to calculate the age of a human by entering the date of birth
C++ Program to convert the upper to lower and lower to upper case letters
C++ Program to calculate the electricity bill of consumed units by the user
C++ Program to convert the small case letters to upper case letters
C++ Program to find out the nth term of its factorial
C++ Program to search for a number from a list by sequential search
C++ Program to find out the exponent of a given number
C++ Program to sort characters in ascending order by using bubble sort
C++ Program to display the text in different colours
C++ Program to convert the decimal number into a binary number
C++ Program to find out the day of the given date, starting from Jan 2001
C++ Program to find out the maximum number from an array
C++ program to display the ASCII values
C++ Program to calculate the area of a room
C++ Program to print students' details using a structure
C++ Program to display a stopwatch on screen for 2 minutes
C++ Program to print a diamond pattern of stars
C++ Program to display the pattern of alphabets
C++ Program to find out the factors of a given number
C++ Program to display the sum of mathematics series
C++ Program to create a game [Find Hidden Word]
C++ Program to display the rectangle on the screen
C++ Program to sort the numbers using selection sort
C++ Program find out whether the given number is prime or not
C++ Program to sort the numbers using insertion sort
C++ Program to display a word in the middle of the screen
C++ Program to create a puzzle game
C++ Program to find out Armstrong numbers from 1 to 500
C++ Program to compare two strings
C++ Program to calculate the number of characters in the given string
C++ Program to calculate the standard deviation of a given range
C++ Program to open a file in binary mode and then get data in that file
C++ Program to use the setw function
C++ Program to create a file in binary mode and then put data in that file
C++ Program to display the Fibonacci series using a function
C++ Program to count the characters, tabs, and vowels in a line from a file
C++ Program to find out the raise to a power using recursion
C++ Program to copy data from one file to another file
C++ Program to find out the prime numbers from a given range
C++ Program to count the number of lines in a file
C++ Program to calculate the square root of a given number
C++ Program to copy a string into a file, then read it and display it on the screen
C++ Program to print the values of a pointer character array
C++ Program to create a file in text mode, write and then read data from the file
C++ Program to access the value of a variable using a pointer
C++ Program to use a friend class
C++ Program to display the address of a variable
C++ Program to display the distance in feet and inches
C++ Program for Matrix Multiplication
C++ Program to use a destructor
C++ Program to create user define header file
C++ Program to calculate the multiplication of two numbers without using the * symbol
C++ Program to find out the smallest number from the given numbers
C++ Program to search a record from a file
C++ Program to search a record from a binary file
C++ Program to open a file in binary mode and count the total records
C++ Program to inherit the class
C++ Program to overload binary operators
C++ Program to overload [] binary operator
C++ Program for binary operator overloading
C++ Program to display the file using the command line of the compiler
C++ Program to update the record in binary mode
C++ Program to search the record in binary file
C++ Program to display a message by using multiple virtual functions
C++ Program to display a message by using a virtual function
C++ Program to multiply three numbers using a friend function
C++ Program to override a function

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes