over 9 years ago
Structures in C++ is a collection of dissimilar data types .Structures is denoted by struct keyword .In structures we can access different data in a single block.It is usually used to keep the track of different kinds of records in a single block.Now am discussing an example illustrating the records of an employee in a company.
- #include <iostream>
- using namespace std;
- struct employee
- {
- char name[100];
- int employee ID;
- int age;
- int account no.;
- float salary;
- };
- int main() {
- employee E1;
- cout << "Enter your Full name: ";
- cin.get(E1.name, 100);
- cout << Enter your employee ID: ;
- cin >> E1.emplyee ID;
- cout << "Enter your age: ";
- cin >> E1.age;
- cout << "Enter your account no.: ";
- cin >> E1.account no.;
- cout << "Enter your salary: ";
- cin >> E1.salary;
- cout << "\nDisplay Records ." << endl;
- cout << "Name: " << E1.name << endl;
- cout << Employee ID: <<E1.Employee ID<< end1;
- cout <<"Age: " << E1.age << endl;
- cout <<"Account no.: " << E1.account no. << endl;
- cout << "Salary: " << E1.salary;
- return 0;
- }
#include <iostream> using namespace std; struct employee { char name[100]; int employee ID; int age; int account no.; float salary; }; int main() { employee E1; cout << "Enter your Full name: "; cin.get(E1.name, 100); cout << Enter your employee ID: ; cin >> E1.emplyee ID; cout << "Enter your age: "; cin >> E1.age; cout << "Enter your account no.: "; cin >> E1.account no.; cout << "Enter your salary: "; cin >> E1.salary; cout << "\nDisplay Records ." << endl; cout << "Name: " << E1.name << endl; cout << Employee ID: <<E1.Employee ID<< end1; cout <<"Age: " << E1.age << endl; cout <<"Account no.: " << E1.account no. << endl; cout << "Salary: " << E1.salary; return 0; }
Output
- Enter Your Full nam Outpute: Samakshi Raheja
- Enter your Employee ID:2245
- Enter your age: 25
- Enter your account no.:130002345
- Enter your salary: 12000.45
- Display Records.
- Name: Samakshi Raheja
- Employee ID:2245
- Age: 25
- Account no.:130002345
- Salary: 12000.45
Enter Your Full nam Outpute: Samakshi Raheja Enter your Employee ID:2245 Enter your age: 25 Enter your account no.:130002345 Enter your salary: 12000.45 Display Records. Name: Samakshi Raheja Employee ID:2245 Age: 25 Account no.:130002345 Salary: 12000.45
0 Comment(s)