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
Add Complex Numbers by Passing Structure to a Function This program takes two complex numbers as structures and adds them with the use of functions. Example: Source Code to Add Two Complex Numbers // Complex numbers are entered by the user #include <iostream> using namespace std ; typedef struct complex { float real ; float imag ; } complexNumber ; complexNumber addComplexNumbers ( complex , complex ); int main () { complexNumber n1 , n2 , temporaryNumber ; char signOfImag ; cout << "For 1st complex number," << endl ; cout << "Enter real and imaginary parts respectively:" << endl ; cin >> n1 . real >> n1 . imag ; cout << endl << "For 2nd complex number," << endl ; cout << "Enter real and imaginary parts respectively:" << endl ; cin >> n2 . real >> n2 . imag ; ...
Comments
Post a Comment