Structues and Functions
71Requirements
- Basic knowledge of structure
- Programming knowledge
- Compiler
Function decomposes any complex program into several manageable modules. Each module is referred as function. Functions are compiled separately. So, they can be tested separately. At last, all the functions are invoked to the main program.
Structure can be passed to the function as a single variable.
In this page, one program is implemented using functions and structue.
Program
Write a program which can collects several information such as employee id, sex, age etc. and can display the entered information to the standard display by using functions and structures.
Program for functions and structure
#include<iostream.h>
// definition of structure
struct company{
long int employee_id;
char sex;
int age ;
};// object defination of the structure company employee;
int main(){
company employee;
// function definition
void information(company employee);
void display(company employee);
cout << "A program for collecting information form"
cout << "the employee using functions and structuer";
//function calling
information(employee);
display(employee);
cin.get();
return 0;
}
void information(company employee){
cout << "Enter the following information:" << endl;
cout << endl;
cout << "Employee ID:"; cin >> employee.employee_id;
cout << "Sex :"; cin >> employee.sex;
cout << "Age :"; cin >> employee.age;
cout << endl;
}void display(company employee){
cout << "Recorded information of the employees:";
cout << endl;
cout << "ID Sex Age" << endl;
cout << employee.employee_id << "\t";
cout << employee.sex << "\t";
cout << employee.age << endl;
}
Output of the program
|
Learn Objective-C for Java Developers
Price: $21.95
List Price: $39.99 |
|
Java Spektrum C-W Objekt Spektrum
Price: $163.22
|
|
c-jump Computer Programming Board Game
Price: $29.99
|
|
Cubavera Men's Long Sleeve Mock Neck Full Zip Raglan Sweater,Java,Medium
Price: $39.99
List Price: $68.00 |
Short discussion of the program
For this program, the structure is defined as follows:
struct company{
long int employee_id;
char sex;
int age ;
};
The structure object is defined by the following code line:
company employee;
This program has two functions. They are:
void information(company employee); void display(company employee);
"Information(company employee)" is used to collect data form the user. And "display(company employee)" is used to display the entered information to the screen.
By using the functions, the program is modularized and easily to understand.
More about "Structuers"
- Write a C/C++ program for displaying today's date by...
Programming Tutorials : C/C++ Programming It's a simple program to start learning structure in C/C++. This program will display today's date. Suppose today's date is 30.10.2008. So, the output of the program... - Structures and arrays
Programming Tutorials : C/C++ Programming Structure and array can be implemented together. An array is a group of identical data items. All array elements are sorted consecutive memory location under a... - Nested Structures : Structures within Structures
Programming Tutorials : C/C++ Programming Structures can be implemented with functions and arrays. Moreover, structures can be implemented as the member of other structure. This is termed as structure within... - Structues and Functions
Programming Tutorials : C/C++ Programming Function decomposes any complex program into several manageable modules. Each module is referred as function. Functions are compiled separately. So, they can be...
Give your opinion.
Is the tutorial helpful?
See results without votingMy recent activities
- Fresh and unique contents for Search Engine Optimization: The secret talks of SEO and generating site contents
Millions of websites with billions of webpages are available in the cyberspace. But only a few of the pages are getting real popularity everyday. Google, Yahoo and Bing are the major search engine.... - 2 weeks ago
- Free malware protection with Portable Anti Trojan Elite: The best malware blocker and malware remover for your compter
Recently malware is spreading very rapidly. Malware is a type of software which is designed specifically to damage or disrupt a system, such as a trojan horse or a spyware or a keylogger. If your PC... - 2 weeks ago
- rundll32.exe - Application Error â The memory could not be "read". Click on OK to terminate the program.
Windows operating system is corrupted due to several virus infections. One such type of common infection is rundll32.exe - Application Error. Due to virus infection, rundll32.exe or such type of... - 3 weeks ago
PrintShare it! — Rate it: up down flag this hub









