Nested Structures in C++

s tructures n.w
1 / 8
Embed
Share

Learn about implementing nested structures in C++ to organize data effectively. Explore examples and syntax for creating and accessing nested structures.

  • C++
  • Nested Structures
  • Syntax
  • Examples
  • Accessing

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. STRUCTURES IN C++ LANGAUGE Setting By : A. L. Waleed Rasheed Fourteen Lecture

  2. Structures: Syntax Struct [struct type name]{ [type variable_name;] } [structures variables]; Note : use struct to group variables into single record. Example: Struct my_struct { Char name[30]; Float avr; } my_stud; To access elements in a structure use a record selector(.), like this: my_stud.name or my_stud.avr And to declare additional variables from structures write this: struct my_struct my_stud[100]; : my_stud name avr char* float

  3. - Sample Example : #include <iostream.h> void main(void) { struct { int id; float avr; } stu; cin>>stu.id; cin>>stu.avr; cout<<"Student No."<<stu.id<<endl; cout<<"average="<<stu.avr; } stu id avr int float

  4. EX//read 10 record to students contains (id,avr ) fields? #include <iostream.h> void main() { struct { int id; float avr; } stu[10]; stu[10] id avr 44 66 88 77 44 60 90 65 77 87 1 2 3 4 5 6 7 8 9 10 for(int i=0;i<10;i++) { cin>>stu[i].id; cin>>stu[i].avr; } for(i=0;i<10;i++) { cout<<"Student No."<<stu[i].id<<endl; cout<<"average="<<stu[i].avr<<endl; } }

  5. EX//W. P. section to read 10 record to students contains (id,avr ) fields and find id to largest average? larg=stu[0].avr; for (i=0;i<10;i++) if (stu[i].avr>larg) id avr 44 66 88 77 44 60 90 65 77 87 1 2 3 4 5 6 7 8 9 10 { larg=stu[i].avr; loc=i;} cout<<stu[loc].id<<stu[loc].avr; }

  6. EX//W. P. to read 10 record to students contains (name , avr ) fields and find count of succ. student? #include<iostream.h> #include<stdio.h> void main() { struct { char name[80]; float avr; } stu[10]; for (int i=0;i<10;i++) { gets(stu[i].name); cin>>stu[i].avr; } int k=0; for (int i=0;i<10;i++) if (stu[i].avr>=50) k++; cout<<"count of succ. student = "<<k; } stu[10] name avr ali alaa raad rana zahraa salam ahmed walaa maha wasam 44 66 88 77 44 60 90 65 77 87

  7. Q//An example about Nested structure: #include<iostream.h> struct student { char name[80]; int age; struct birth_date { int year; int month; int day; } void main() { student stud; cin>>stud.name; cin>>stud.age; cin>>stud.ddd.year; cin>>stud.ddd.month; cin>>stud.ddd.day; if (stud.age>60) cout<<"finshed"<<endl; } ddd; };

  8. Homework Q1 / W. P. section to read 40 record to students contains (name,avr ) fields and find count of succ. and fail? Q2/ W. P. section to read 40 record to students contains (id,avr ) fields and apply descending sort depending on average?

Related


More Related Content