Hello Friends! We are just for you, throught this website you can learn c++
and clear your concepts.
C++ Program to Store and Display Information Using Structure
Get link
Facebook
X
Pinterest
Email
Other Apps
C++ Program to Store and Display Information Using Structure By Simple Method
This program stores the information (name, fname id and course ).
In this program, a structure, student is created.
This structure has three members: name (char), fname (char) and id (int ) and course (char ).
#include<iostream>
using namespace std;
// declaring the strct
struct Student{
int id;
char name[10];
char fname[10];
char course[10];
};
int mian()
{
//create the struct type object
Student s1;
//get student info
cout<<"Enter Your Name "<<endl;
cin>>s1.name;
cout<<"Enter Your Id "<<endl;
cin>>s1.id;
cout<<"Enter Your Father Name "<<endl;
cin>>s1.fname;
cout<<"Enter Your Course Title"<<endl;
cin>>s1.course;
//display student info
cout<<"Your Name is"<<s1.name;
cout<<"Your Id is"<<s1.id;
cout<<"Your Father Name is"<<s1.fname;
cout<<"Your Course Title is"<<s1.course;
return 0;
}
Learn Structures in C++ And See More Example related to Structures
Structures A data structure is a group of data elements grouped together under one name. These data elements, known as members , can have different types and different lengths. For example: You want to store some information about a person: his/her name, citizenship number and salary. You can easily create different variables name, citNo, salary to store these information separately. However, in the future, you would want to store information about multiple persons. Now, you'd need to create different variables for each information per person: name1, citNo1, salary1, name2, citNo2, salary2 You can easily visualize how big and messy the code would look. Also, since no relation between the variables (information) would exist, it's going to be a daunting task. A better approach will be to have a collection of all related information under a single name Person , and use it for every person. Now, the code looks much cleaner, readable...
object oriented programming c++ structures in c++ This program store the information (name, fname id and department). #include<iostream> using namespace std; // declaring the strct struct Student{ string id; string name; string fname; string depart; }; int main() { Student s1; //get student info cout<<"Enter Your Details "<<endl<<endl; cout<<"Enter Your ID "<<endl; getline(cin,s1.id); cout<<"Enter Your Department "<<endl; getline(cin,s1.depart); cout<<"Enter Your Name "<<endl; getline(cin,s1.name); cout<<"Enter Your F'Name' "<<endl; getline(cin,s1.fname); //displaying student info cout<<"Displaying Student Info"<<endl; cout<<"Your ID is"<<s1.id<<endl; cout<<"Your Name is"<<s1.name<<endl; cou...
Comments
Post a Comment