This document discusses structures and unions in C++. It defines a structure as a collection of related data items of different types stored together in memory. Structures allow defining custom data types that group various member variables. Unions also define custom data types but allow different types of variables to share the same memory space, taking up only as much space as its largest member. The document provides examples of declaring, defining, initializing, accessing members, and using structures and unions in C++ programs. It also compares the key differences between structures and unions.
Constructors, Destructors, call in parameterized Constructor, Multiple constructor in a class, Explicit/implicit call, Copy constructor, Dynamic Constructors and call in parameterized Constructor
Constructors, Destructors, call in parameterized Constructor, Multiple constructor in a class, Explicit/implicit call, Copy constructor, Dynamic Constructors and call in parameterized Constructor
Inheritance is the capability of a class to use the properties and methods of another class while adding its own functionality.
Enables you to add new features and functionality to an existing class without modifying the existing class.
The Key Difference between a List and a Tuple. The main difference between lists and a tuples is the fact that lists are mutable whereas tuples are immutable. A mutable data type means that a python object of this type can be modified. Let's create a list and assign it to a variable.
● Concept of Structure and Union
● Declaration and Initialization of structure and union
● Nested structures
● Array of Structures
● Passing structure to functions
Inheritance is the capability of a class to use the properties and methods of another class while adding its own functionality.
Enables you to add new features and functionality to an existing class without modifying the existing class.
The Key Difference between a List and a Tuple. The main difference between lists and a tuples is the fact that lists are mutable whereas tuples are immutable. A mutable data type means that a python object of this type can be modified. Let's create a list and assign it to a variable.
● Concept of Structure and Union
● Declaration and Initialization of structure and union
● Nested structures
● Array of Structures
● Passing structure to functions
A Structure is a convenient tool for handling a group of logically related data items. A collection of one or more variables, typically of different types, grouped together under a single name is known as structure.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
This is a presentation by Dada Robert in a Your Skill Boost masterclass organised by the Excellence Foundation for South Sudan (EFSS) on Saturday, the 25th and Sunday, the 26th of May 2024.
He discussed the concept of quality improvement, emphasizing its applicability to various aspects of life, including personal, project, and program improvements. He defined quality as doing the right thing at the right time in the right way to achieve the best possible results and discussed the concept of the "gap" between what we know and what we do, and how this gap represents the areas we need to improve. He explained the scientific approach to quality improvement, which involves systematic performance analysis, testing and learning, and implementing change ideas. He also highlighted the importance of client focus and a team approach to quality improvement.
Ethnobotany and Ethnopharmacology:
Ethnobotany in herbal drug evaluation,
Impact of Ethnobotany in traditional medicine,
New development in herbals,
Bio-prospecting tools for drug discovery,
Role of Ethnopharmacology in drug evaluation,
Reverse Pharmacology.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
What is the purpose of the Sabbath Law in the Torah. It is interesting to compare how the context of the law shifts from Exodus to Deuteronomy. Who gets to rest, and why?
How to Split Bills in the Odoo 17 POS ModuleCeline George
Bills have a main role in point of sale procedure. It will help to track sales, handling payments and giving receipts to customers. Bill splitting also has an important role in POS. For example, If some friends come together for dinner and if they want to divide the bill then it is possible by POS bill splitting. This slide will show how to split bills in odoo 17 POS.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
How to Create Map Views in the Odoo 17 ERPCeline George
The map views are useful for providing a geographical representation of data. They allow users to visualize and analyze the data in a more intuitive manner.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
1. STRUCTURE &
UNION
Ms. Davinder Kaur
Assistant Professor
Department of Computer Applications
Chandigarh Group of Colleges, Landran
2. STRUCTURE
A Structure is a collection of related data items which can be of different types held
together in a single unit.
All the elements of structure are stored at contiguous memory locations.
The data items enclosed within a structure are known as its members which can be
either of int, float, char etc.
3. Structure Declaration
A structure declaration specifies the grouping of
variables of different types in a single unit.
The syntax for declaring a structure in C++ is-
Example of Structure Declaration is-
struct struct_name struct student
{ {
data_type member1; int rollno;
data_type member2; char name[20];
…….. float marks;
data_type membern; };
};
4. Structure Definition
The structure definition creates structure variables and allocates
storage space for them.
The individual members of the structure variables are stored in
contiguous memory locations.
For example-
struct student s1,s2;
Or student s1,s2;
struct student
{
int rollno;
char name[20];
float marks;
}s1,s2;
Here s1,s2 are two structure variables of type student.
5. Accessing Structure Members
The members can be accessed using a dot operator(.)
or an arrow operator(->).
The use of extraction operator(>>) and insertion
operator(<<) to input and display the members of
structure variable s1.
cin>>s1.rollno>>s1.name>>s1.marks;
cout<<s1.rollno<<s1.name<<s1.marks;
6. Example of Accessing members-
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
struct student
{
int rollno;
char name[20];
float marks;
};
void main()
{
struct student s1; clrscr();
cout<<"Enter roll no, name,marks"; cin>>s1.rollno>>s1.name>>s1.marks;
cout<<endl; cout<<"Roll no is:"<<s1.rollno<<endl;
cout<<"Name of student is:"<<s1.name<<endl;
cout<<"Marks are:"<<setprecision(2)<<s1.marks<<endl;
getch();
}
7. Structure Initialization
A structure variable is initialized with values that are to be assigned to its members
within the braces.
Example-
struct employee
{
int emp_no;
char emp_name[20];
int dept_id;
double salary;
};
Defining and initialize structure variable emp1 of type employee as follow:
employee emp1={101,”Aman”,1125,20000};
8. Example of Structure Initialization
#include<iostream.h>
#include<conio.h>
struct employee
{
int emp_no;
char emp_name[20];
int emp_id;
double salary;
};
void main()
{
struct employee emp1={101,"Davinder",1125,20000};
clrscr();
cout<<"Employee Details are-"<<endl;
cout<<"Employee number is "<<emp1.emp_no<<endl;
cout<<"Employee name is "<<emp1.emp_name<<endl;
cout<<"Employee Id is "<<emp1.emp_id<<endl;
9. Structure Assignment
The value of one structure variable is assigned to another
variable of same type using assignment statement. If s1 and s2
are structure variable of type student then the statement
s2=s1;
assign value of structure variable s1 to s2.
10. Example of Structure Assignment
#include<iostream.h>
#include<conio.h>
struct student
{
int rollno;
char name[20];
float marks;
};
void main()
{
struct student s1={101,"Simran",50.677654};
struct student s2;
clrscr();
s2=s1;
cout<<"Roll number is "<<s2.rollno<<endl;
cout<<"Name is "<<s2.name<<endl;
cout<<"Marks are "<<s2.marks<<endl;
getch();
}
11. Nesting of Structure (Structure
within Structure)
When a structure contains another structure, it is
called nested structure.
In other words, a member of a structure is a
variable of another structure. This process in
which a structure can appear within another
structure is known as nesting of structure.
12. Syntax for structure within
structure or nested structure
struct structure_name1
{
datatype variable_name;
datatype varaiable_name;
};
struct structure_name2
{
datatype variable_name;
datatype variable_name;
struct structure_name1 obj;
};
13. Example of Nesting Structure#include<iostream.h>
#include<conio.h>
struct date
{
int day;
int month;
int year;
};
struct employee
{
int emp_code;
char emp_name[20];
int dept_id;
float sal;
date doj;
};
void main()
{
employee emp1;
clrscr();
cout<<"Enter employee code, name of employee ";
cin>>emp1.emp_code>>emp1.emp_name;
cout<<"Enter dept id, salary";
cin>>emp1.dept_id>>emp1.sal;
cout<<"Enter date,month and year of joining";
cin>>emp1.doj.day>>emp1.doj.month>>emp1.doj.year;
cout<<endl;
cout<<"Displaying information of Employee is:"<<endl;
cout<<"Employee Code is:"<<emp1.emp_code<<endl;
cout<<"Name of Employee
is:"<<emp1.emp_name<<endl;
cout<<"Department id is:"<<emp1.dept_id<<endl;
cout<<"Salary is:"<<emp1.sal<<endl;
cout<<"Joining date is:"<<emp1.doj.day<<"-
"<<emp1.doj.month<<"-"<<emp1.doj.year;
getch();
}
14. Array of Structure
Array of structure refers to an array in which each array
element is a structure variable of same type.
For Example-
struct student
{
int rollno;
char name[20];
float marks;
}s[10]; //array of structure
15. Initialization of Array of Structure
An array of structures can be assigned some initial values just as any other build in
types.
For Example-
struct student
{
int rollno;
char name[20];
};
………….
………..
Student s[3]={101,”Aman”,
102,”Vicky”,
103,”Rishi”
};
16. Example of Array of Structure
#include<iostream.h>
#include<conio.h>
struct student
{
int rollno;
char name[20];
float marks;
};
void main()
{
student s[5];
int n;
clrscr();
cout<<"Enter number of students";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"Enter roll no,name, marks";
cin>>s[i].rollno>>s[i].name>>s[i].ma
rks;
}
cout<<"Displaying Students Information
"<<endl;
for(i=0;i<n;i++)
{
cout<<"Rollno is "<<s[i].rollno<<endl;
cout<<"Name is "<<s[i].name<<endl;
cout<<"Marks is "<<s[i].marks<<endl;
}
getch();
}
17. Structures & Functions
Individual members of a structure can be passed to a
function as argument in the function call. This method
of passing individual member is same as that of passing
variable of any primitive type.
18. Example of Passing Structure to function
#include<iostream.h>
#include<conio.h>
struct employee
{
int emp_code;
char name[20];
double sal;
};
void main()
{
void display(employee);
//Function Declaration
employee emp1={101,"Ritu",12000};
clrscr();
cout<<"Details of Employee are "<<endl;
display(emp1);//Function Call
getch();
}
void display(employee e)
{
cout<<"Code of employee
is:"<<e.emp_code<<endl;
cout<<"name of Employee is
"<<e.name<<endl;
cout<<"Salary is "<<e.sal;
}
19. Structure With Pointers
Like pointers to int, char and other data-types, pointers also pointing to
structures. These pointers are called structure pointers.
Syntax is-
struct structure_name
{
data-type member-1;
data-type member-1;
data-type member-1;
data-type member-1;
};
int main()
{
struct structure_name *ptr;
}
20. Example of structure with pointer
#include<iostream.h>
#include<conio.h>
struct student
{
char name[20];
int rollno;
};
void main()
{
struct student s={"Raman",123};
struct student *ptr;
clrscr();
ptr=&s;
cout<<"name and roll no. of student is
"<<s.name<<"t"<<s.rollno;
cout<<"nname and roll no is "<<ptr-
>name<<"t"<<ptr->rollno;
getch();
}
21. Union
A union is a user-defined data type like structure. The union
groups logically related variables into single unit.
The union data type allocate the space equal to space need to hold
the largest data member of union.
The union allows different types of variable to share same space in
memory.
Syntax is-
union <union_name>
{
datatype variable_name;
datatype variable_name;
};
23. Difference between Structure & Union
Structure occupies memory for all its members whereas Union will
not take memory for all its members. It will take the memory
occupied by the highest memory occupying member.
In union, one block is used by all members of the union but in case
of structure, each member has its own memory space.
Union is the best environment where memory is limited as it
shares the allocated memory. But structure cannot be implemented
in shared memory.
In union, only one member can be assigned a value at a time. But
in structures, all the members can be assigned values at a time.
In structure, value assigned to one member cannot cause change in
other members, where as in union it causes change in values of
other members.