Nested Structures : Structures within Structures

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 structure.  
When a structure is decleared as the member of another structue, it is called
Structure within a structure. It is also known as nested structure.
Example of nested structure
One example of nested structure is given below:
struct date{
// members of structure
 int day;
int month;
int year;
};

struct company{
char name[20];
long int employee_id;
char sex[5];
int age;
struct date dob;};
Write a program which can collect employee information (such as employee name, id, sex, date of birth etc.) of a company and display the collected information t
#include
#include
#define MAX 1000

// structure block defination
struct date{
// members of structure definition
int day;
int month;
int year;
};

struct company{
char name[20];
long int employee_id;
char sex[5];
int age;
// nested block defination
struct date dob;
};

// structuer object defination
company employee[MAX];
// main function starts
int main(){
company employee[MAX];
int n;
cout << "A program for collecting employee information";
cout << endl;
cout << "And displaying the collected information";
cout << endl << endl;
cout << "How many employees:";
cin >> n;
cout << endl;
// functions defination
void CollectInformtion(company employee[MAX], int n);
void Display(company employee[MAX], int n);

// functions calling
CollectInformtion(employee, n);
Display(employee, n);
cin.get();
return 0;
}
// collecting information form the user
void CollectInformtion(company employee[MAX], int n){
cout << "Enter the following information:";
cout << endl << endl;

for (int i=1; i<=n; i++){
cout << "Enter information for employee no: " << i;
cout << endl;
cout << "Name :"; cin >> employee[i].name;
cout << "ID :"; cin >> employee[i].employee_id;
cout << "Sex :"; cin >> employee[i].sex;
cout << "Age :"; cin >> employee[i].age;
cout << "Date of Birth:" << endl;
cout << "Day :"; cin >> employee[i].dob.day;
cout << "Month :"; cin >> employee[i].dob.month;
cout << "Year :"; cin >> employee[i].dob.year;

cout << endl;
}
}
// displaying entered information to the standard output
void Display(company employee[MAX], int n){
cout << "Employee entered information:";
cout << endl;
cout << "Name ID Sex Age Date of Birth" << endl;
for (int i=1; i<=n; i++){
cout << employee[i].name << "\t";
cout << employee[i].employee_id << "\t";
cout << employee[i].sex; cout << "\t";
cout << employee[i].age; cout << "\t";
cout << employee[i].dob.day << ".";
cout << employee[i].dob.month << ".";
cout << employee[i].dob.year ;

cout << endl;
}
}
Discussion of the above program
At first, the graphical representation of the program is given below:
613294_f260

Graphical representation of the structure

So, the code block will be:
struct date{
// members of structure
int day;
int month;
int year;
};
struct company{
char name[20];
long int employee_id;
char sex[5];
int age;
struct date dob;
};


Look "struct date dob;" is used to link the nested structure.
To initialize the values in nested structue it uses like the followings:
employee[i].dob.day;
employee[i].dob.month;
employee[i].dob.year;

The program has two functions:
void CollectInformtion(company employee[MAX], int n);
void Display(company employee[MAX], int n);

Function "CollectInformtion()" is used to take inputs from the users.And function "Display()" is used to display the final output. 

Writing First C/C++ Program : A tutorial of C/C++ Programming

What is C programming?
C is :
  • a programming language  
  • a structured language  
  •  a general purpose programming language  
  • developed basically for developing system programming  
  • also used for application programming  
  • developed by Dennis Ritchie at Bell Lab many  
  • languages are greatly influenced by C (for example: C++)
  • low level language
What is C++ programming?
C++ is :
  • object-oriented programming language
  • C++ is a super-set of C
  • supports almost all features of C
  • simplifies memory management
  • supports several features-
  • encapsulation
  • inheritance
  • polymorphism
  • created by Bjarne Stroustrup
Writing the Program : Learn by Example
Programs are developed or implemented by programmer. For successful implementation of program or programs, three steps are required:
  • Step 01 : Writing the program
  • Step 02 : Compiling i.e. checking program's syntax to find errors and solving  
  • Step 03 : Running the program

Step 01 : Writing the program
Compilers are required for writing any C or C++ program. Most common compilers are Borland C++, Microsoft C++, GNU C++ etc. The compile choosing is fully depends on you.
In this article, the program will be implemented by using "Turbo C++" compiler. Here, a simple program will be coded. We call it "Hello World" program. The program code is given below:
"Hello World" Program
/********************************/
/* A simple Hello World program */
/********************************/
#include
#include

/* declertion of main function */
int main(){
cout << "Hello World !!";
cout << endl;
cin.get();
return 0;
}
/* Program ends here */

This is the actual needed code. But to understand the program, more details is explained below:
Explained version of "Hello World" Program
/********************************/
/* A simple Hello World program */
/********************************/
#include
#include
// declearation of header directives
/* declertion of main function */
int main(){
// main function starts by a "{" bracket
cout << "Hello World !!";
// the above line prints the text to the output
cout << endl;
// inserts a new line break
cin.get();
// waits to take a hit form the user to end
return 0;
// returns value 0
}
// main function ends by a "}" bracket
/* Program ends here */


Explanation of Headers
The program begins with a "#include" . It indicates a preprocessor directive. By writing such it tells the compile to insert code form the header "iostream" to the program. It's also necessary to access several library functions. So, you have to include several required header files based on your program. 
Explanation of Comments
In programming, comments are used to describe the program's work or the use of any function etc. Comments are ignored by compiler. Comments can be implemented by the following ways:
  • /* text comment */: Compiler ignores Al's between /* and */. This means text comment.  
  • /** documentation comment*/: Also ignored by compiler and used to as a documentation comment  
  • // text: Compiler ignores all from // to the end of the line.
Explanation of "main()" Function
Every C/C++ program must contains one "main()" function. 
"int main()" implies the compiler that there exists a function named as "main" and it is integer type. It may also be void or float or double type. If you use int than you have to return the value.
"main()" function always stayed curly braces ( { and } ). They indicate the beginning and ending of the program block.
In the "main()" function block, there is "cout" object and after it "<<" symbol. "<<" is called "insertion operators". It indicates the output. After the "<<" symbol there are some text which are between two double inverted commas (" Hello World !! "). The text which are in between the double inverted commas are seen as the output when the program runs.
Every expression in C++ program ends with a semicolon (;). 
Explanation of "cout"
"\n" refers a single character and means newline. If you use it, then the cursor will go to the next line. You can also use "endl" which also does the same task. 
Explanation of "cin.get()"
The function call "cin.get()" reads the inputs and waits until the user hits the enter key of keyboard.  
Step 02 : Compiling the program
After writing the program, it's time to run your simple program. But before that you have to check whether the program contains any error or not. If it has any error, you need to solve the error or errors.
For compiling your program, you have to press "Alt-F9". It then compiles and shows whether any error exists or not. If you find any error then try to solve them.
Explanation of "return 0"
Finally, "return 0" which returns O. It's use is mandatory if we use integer or float etc. type for declaration of "main()" function. To avoid this line, you can use "main()" function as void type.  

1. What are the differences between C and C++?

  • C++ supports OOP (Object Oriented Programming) concept. But C does not.  
  • C++ allows to create classes but C does by structures.  
  • C++ applications are slower than C programs during run-time.  
  • C++ supports polymorphism, inheritance, encapsulation. But C does not support.
2. Which function must exists in any C/C++ program?

"main()" function 

3. C++ programming supports which type of features?

  • encapsulation
  • inheritance
  • polymorphism 
4. Name some of the common compilers.
  • Borland C++
  • Microsoft C++
  • GNU C++

How to: Write and compile C programs on Mac OS X

How to: Write and compile C programs on Mac OS X
program
During a programming class back in 2006, I had to find a way to write and compile C programs on my iBook G4. This was one of the ways I found to do that job.
Required:
  • Apple Developer Tools (available on OS X Install DVD)
  • A text editor (I use TextWrangler)
Steps:
  • Install Apple Developer Tools on the Mac OS X Install DVD by inserting Disk 1 and choosing Developer Tools.
  • Write a program with a text editor and save it with the extension .c
  • Open Terminal by navigating to Applications > Utilities > Terminal
  • Type gcc with a space afterwards
  • compile
  • Drag the file with the .c extension to the Terminal window to place the location of the file.
  • Press Enter.
  • This will generate a file called a.out inside your user folder.
  • Type ~/a.out
  • Press Enter.
  • Watch your program come alive!

Using SSH with Terminal in Mac OS X

Terminal with SSH:
To begin using
Terminal icon to launch the application. Terminal is located in the Utilities folders in the Applications folder.
icon
Double-click the
  • Terminal window will appear with a command prompt.
    cmdprompt
    A
  • ssh your-login-name@terpconnect.umd.edu.
    ssh
    At the prompt, type in
  • Directory password.
    password
    You will be prompted to type in your
  • TerpConnect command prompt will appear.
    yprompt
    Once you successfully login, a

  • What is GPU Computing?

    GPU computing or GPGPU is the use of a GPU (graphics processing unit) to do general purpose scientific and engineering computing. The model for GPU computing is to use a CPU and GPU together in a heterogeneous co-processing computing model. The sequential part of the application runs on the CPU and the computationally-intensive part is accelerated by the GPU. From the user’s perspective, the application just runs faster because it is using the high-performance of the GPU to boost performance. gpu-computing-feature The GPU has evolved over the years to have teraflops of floating point performance. NVIDIA revolutionized the GPGPU and accelerated computing world in 2006-2007 by introducing its new massively parallel architecture called “CUDA”. The CUDA architecture consists of 100s of processor cores that operate together to crunch through the data set in the application. The success of GPGPUs in the past few years has been the ease of programming of the associated CUDA parallel programming model. In this programming model, the application developer modify their application to take the compute-intensive kernels and map them to the GPU. The rest of the application remains on the CPU. Mapping a function to the GPU involves rewriting the function to expose the parallelism in the function and adding “C” keywords to move data to and from the GPU. The developer is tasked with launching 10s of 1000s of threads simultaneously. The GPU hardware manages the threads and does thread scheduling. The Tesla 20-series GPU is based on the “Fermi” architecture, which is the latest CUDA architecture. Fermi is optimized for scientific applications with key features such as 500+ gigaflops of IEEE standard double precision floating point hardware support, L1 and L2 caches, ECC memory error protection, local user-managed data caches in the form of shared memory dispersed throughout the GPU, coalesced memory accesses and so on.