Program to Store Information in Structure and Display it in CPP (C plus plus)

Program to Store Information in Structure and Display it in CPP (C plus plus)

In this tutorial, we will learn about the Program to Store Information in Structure and Display it in CPP (C plus plus). 

#include <iostream>

using namespace std;

struct stu
{
    int rol;
    float marks;
    char n[50];
} 
k[10];

int main()
{
    cout <<"Please enter information of students: "<<endl<<endl;

    
    for(int i=0;i<3;++i)
    {
        k[i].rol = i+1;
        
        cout<<"For Roll No: "<<k[i].rol<<","<<endl;

        cout<<"Please enter name: ";
        cin>>k[i].n;

        cout<<"Please enter marks: ";
        cin>>k[i].marks;

        cout<<endl;
    }

    cout<<"Showing Information: "<<endl;

    for(int i=0;i<10;++i)
    {
        cout<<endl<<"Roll No: "<<i+1<<endl;
        cout<<"Name: " <<k[i].n<<endl;
        cout<<"Marks: "<<k[i].marks<<endl;
    }

    return 0;
}

Output:

Program to Store Information in Structure and Display it in CPP (C plus plus)
Program to Store Information in Structure and Display it in CPP (C plus plus)

Programs without structure

Programs to Store and displays Information using For Loop (without structure)

Let’s see the Program to Store and displays Information using for loop(without structure).

#include<iostream>
using namespace std;
struct stu
{
	int roll;
	float marks;
	char name[50];
}
p[10];
int main()
{
	cout<<"please enter information of students: "<<endl<<endl;
	
	for (int i=0; i<3; ++i)
	{
		p[i].roll = i+1;
		cout<<"For Roll no. "<<p[i].roll<<":"<<endl;
		
		cout<<"please enter name: ";
		cin>>p[i].name;
		
		cout<<"please enter marks: ";
		cin>>p[i].marks;
		cout<<endl;
	}
	cout<<endl<<"showing information: "<<endl;
	for(int i=0; i<3; ++i)
	{
		cout<<"Roll No.: "<<i+1<<endl;
		cout<<"Nmae: "<<p[i].name<<endl;
		cout<<"Marks: "<<p[i].marks<<endl<<endl;
	}
	system("pause");
}

Programs to Store and displays Information using do-while Loop (without structure)

Let’s see the Program to Store and displays Information using the do-while loop (without structure).

#include<iostream>
using namespace std;
struct stu
{
	int roll;
	float marks;
	char name[50];
}
p[10];
int main()
{
	cout<<"please enter information of students: "<<endl<<endl;
	int i=0; 
	do
	{
		p[i].roll = i+1;
		cout<<"For Roll no. "<<p[i].roll<<":"<<endl;
		
		cout<<"please enter name: ";
		cin>>p[i].name;
		
		cout<<"please enter marks: ";
		cin>>p[i].marks;
		cout<<endl;
		i++;
	}
	while (i<3);
	cout<<endl<<"showing information: "<<endl;
	i=0;
	do
	{
		cout<<"Roll No.: "<<i+1<<endl;
		cout<<"Nmae: "<<p[i].name<<endl;
		cout<<"Marks: "<<p[i].marks<<endl<<endl;
		i++;
	}
	while(i<3);
	system("pause");
}

Programs to Store and displays Information using while Loop (without structure)

Let’s see the Program to Store and displays Information using the while loop (without structure).

#include<iostream>
using namespace std;
struct stu
{
	int roll;
	float marks;
	char name[50];
}
p[10];
int main()
{
	cout<<"please enter information of students: "<<endl<<endl;
	int i=0; 
	while (i<3)
	{
		p[i].roll = i+1;
		cout<<"For Roll no. "<<p[i].roll<<":"<<endl;
		
		cout<<"please enter name: ";
		cin>>p[i].name;
		
		cout<<"please enter marks: ";
		cin>>p[i].marks;
		cout<<endl;
		i++;
	}
	cout<<endl<<"showing information: "<<endl;
	i=0;
	while(i<3)
	{
		cout<<"Roll No.: "<<i+1<<endl;
		cout<<"Nmae: "<<p[i].name<<endl;
		cout<<"Marks: "<<p[i].marks<<endl<<endl;
		i++;
	}
	system("pause");
}

Programs to Store and displays Information using User Define Function (without structure)

Let’s see the Program to Store and displays Information using the user defined the function (without structure).

#include<iostream>
using namespace std;
int store(int[],char[],float[]);
int main()
{
	int roll[2];
	char name[2];
	float marks[2];
	int a=1;
	
	cout<<"Please Enter the Infrmation of students:"<<endl<<endl;
	
	store(roll,name,marks);
	 cout<<endl<<"Showing Information:"<<endl;
	 for(int i=0; i<3; i++)
	 {
	 	cout<<endl<<"Roll no.: "<<i+1<<endl;
	 	cout<<"Name: "<<name[i]<<endl;
	 	cout<<"Marks: "<<marks[i]<<endl;
	 }
	 system("pause");
}
int store(int roll[2],char name[2],float marks[2])
{
	for(int i=0;i<3; i++)
	{
		cout<<endl<<"For roll nu. "<<i+1<<":"<<endl;
		roll[i]=i+1;
		cout<<"please enter the Name: ";
		cin>>name[i];
		cout<<"please enter the Marks: ";
		cin>>marks[i];
			
	 } 
}

 

 

Prof.Fazal Rehman Shamil (Available for Professional Discussions)
1. Message on Facebook page for discussions,
2. Video lectures on Youtube
3. Email is only for Advertisement/business enquiries.