Declaring a Structure Globally So That It Is Available Throughout the Program
Autor: kally • April 17, 2015 • Study Guide • 2,684 Words (11 Pages) • 920 Views
Structure1.cpp
#include
#include
#include
#include
// Declaring a Structure globally so that it is available throughout the program.
struct book
{
char title[20]; // Attribute of the structure book.
char author[20]; // Attribute of the structure book.
int edition; // Attribute of the structure book.
char isbn[14]; // Attribute of the structure book.
char publisher[20]; // Attribute of the structure book.
float price; // Attribute of the structure book.
};
void main()
{
clrscr();
cout << "Structure Called book is already created."<< endl;
// Creating objects/entities from the structure. b1 & b2 are known as objects/entities.
book b1, b2;
cout << "Objects b1 & b2 of structure book are created."<< endl;
// Creating objects and initialization simultaneously from the structure.
book b3 = { "Let Us C","YK",4,"81-7656-940-2","BPB",180 };
// Display the contents of the b3 object.
cout << "The content of object b3 is ... " << endl;
cout << "Title : " << b3.title << endl;
cout << "Author : " << b3.author << endl;
cout << "Edition : " << b3.edition << endl;
cout << "ISBN : " << b3.isbn << endl;
cout << "Publisher : " << b3.publisher << endl;
cout << "Price : " << b3.price << endl;
// copying the content of one object of structure into another object.
b1 = b3;
// Shall we repeat all the above statement for b1 object? No, we should find another way to do the job easily.
// .......................Thinking............... //...........................ok..................
// Now pass the whole object into a function as an argument.
// Declaring a function having structure as an argument.
void display(struct book);
// call display function.
cout << "The content of object b1 is ... " << endl;
display(b1);
// Accept the information from the user and store it into b2 object.
cout << "Enter information for b2 object." << endl;
...