SlideShare a Scribd company logo
1.
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
struct student
{
int ID; // 4 bytes
char name[10];//10bytes
float grade; // 4bytes
int age; // 4
char phone[10]; // 10
char e_mail[16]; // 16
};
void display(struct student s)
{
cout<<setw(3)<< s.ID <<setw(12)<< s.name <<setw(8)<< setiosflags (ios::showpoint)<<setprecision(2)<<
s.grade<<setw(5)<<s.age <<setw(10)<< s.phone<< setw(18)<<s.e_mail<<endl;
}
void main()
{
struct student s1={55,"Amir Ali",3.5f,23,"6535418","amir@yahoo.com"};
struct student s2={26,"Mujahid",2.9888f,25,"5362169", "muj@hotmail.com"};
struct student s3={39,"M Jamil",3.108f,30,"2345677","jam@hotmail.com"};
struct student s4={44,"Dilawar",2.7866f,31,"5432186","dil@hotmail.com"};
struct student s5={59,"S.Naveed",2.9f,27,"2345671","navee@yahoo.com"};
cout<<" Students Records Sheetn";
cout<<" ~~~~~~~~~~~~~~~~~~~~~~nn";
cout<<"ID# NAME GRADE AGE PHONE E-MAILn";
cout<<"~~~ ~~~~ ~~~~~ ~~~ ~~~~~ ~~~~~~~n";
display(s1); // structure pass to function
display(s2); // structure pass to function
display(s3);
display(s4);
display(s5);
}
2.
// In this program you will see the structures (members Manipulation),
// Passing structures to functions:
#include <iostream.h>
#include <iomanip.h>
struct S_Details
{
char name [30];
int exam1;
int exam2;
int exam3;
int final;
float sem_ave;
char letter_grade;
};
//inputs the data items for a student, structure
//is passed by reference
struct S_Details get_stu ( )
{
struct STU_GRADES student;
cout << "nnnn Enter the information for a studentn";
cout << " Name: ";
cin.getline (student.name, 30, 'n');
cout << " Exam1: ";
cin >> student.exam1;
cout << " Exam2: ";
cin >> student.exam2;
cout << "exam3: ";
cin >> student.exam3;
cout << "final: ";
cin >> student.final;
return student;
}
//displays a student's info.
//structure is passed by value
void print_stu (struct STU_GRADES stu)
{
cout << "nnnGrade report for: " << stu.name<<endl;
cout << "nexam 1texam 2texam 3tfinaln";
cout << stu.exam1 << "t" << stu.exam2 << "t"<< stu.exam3 << "t" << stu.final;
cout << "nnnsemester average: " << setiosflags (ios::fixed)<< setprecision (2) << stu.sem_ave;
cout << "nsemester grade: " << stu.letter_grade;
}
float calc_ave (int ex1, int ex2, int ex3, int final)
{
float ave;
ave = float (ex1 + ex2 + ex3 + final)/4.0f;
return ave;
}
char assign_let (float average)
{
char let_grade;
if (average >=90)
let_grade = 'A';
else if (average >= 80)
let_grade = 'B';
else if (average >= 70)
let_grade = 'C';
else if (average >= 60)
let_grade = 'D';
else
let_grade = 'F';
return let_grade;
}
int main()
{
struct S_Details stu;
char more;
do
{
//pass the entire structure
Stu = get_stu ( );
//pass elements of the strucutre
stu.sem_ave = calc_ave (stu.exam1, stu.exam2, stu.exam3, stu.final);
//pass elements of the structure
stu.letter_grade = assign_let (stu.sem_ave);
//pass the entire structure
print_stu (stu);
cout << "nnn Enter another student? (y/n) ";
cin >> more;
//grab the carriage return since
//character data is input next
cin.ignore ( );
}
while (more == 'y' || more == 'Y');
return 0;
}

More Related Content

DOCX
Module nco rtl
PPTX
JavaScript Gotchas
PDF
Clojure functions 3
PDF
3分くらいで分かるassert()
PDF
04 2 오버플로 상수 매크로
PPTX
Performance Optimization In Angular 2
DOCX
VISUALIZAR REGISTROS EN UN JTABLE
PDF
FLTK Summer Course - Part VI - Sixth Impact - Exercises
Module nco rtl
JavaScript Gotchas
Clojure functions 3
3分くらいで分かるassert()
04 2 오버플로 상수 매크로
Performance Optimization In Angular 2
VISUALIZAR REGISTROS EN UN JTABLE
FLTK Summer Course - Part VI - Sixth Impact - Exercises

Similar to Codes on structures (20)

PPT
Unit4 (2)
PPSX
C++ programming structure & union
PPT
FP 201 - Unit4 Part 2
PPTX
Structure & union
PDF
Module 5 - Pointer,Structures and Union.pptm.pdf
PPTX
CA2_CYS101_31184422012_Arvind-Shukla.pptx
PPTX
programming fundamentals
PDF
C++ L07-Struct
PPT
C Language Unit-4
PPT
Unit4
PDF
12 2. structure
PPT
358 33 powerpoint-slides_7-structures_chapter-7
PPTX
Structure in C language
PDF
Pointers and Structures
DOCX
Investigatory Project for Computer Science
PPTX
Structure.pptx Structure.pptxStructure.pptxStructure.pptxStructure.pptxStruct...
PPTX
Programming for problem solving-II(UNIT-2).pptx
PPTX
Pf cs102 programming-10 [structs]
PPTX
A10presentationofbiologyandpshyology.pptx
PDF
Structures and Pointers
Unit4 (2)
C++ programming structure & union
FP 201 - Unit4 Part 2
Structure & union
Module 5 - Pointer,Structures and Union.pptm.pdf
CA2_CYS101_31184422012_Arvind-Shukla.pptx
programming fundamentals
C++ L07-Struct
C Language Unit-4
Unit4
12 2. structure
358 33 powerpoint-slides_7-structures_chapter-7
Structure in C language
Pointers and Structures
Investigatory Project for Computer Science
Structure.pptx Structure.pptxStructure.pptxStructure.pptxStructure.pptxStruct...
Programming for problem solving-II(UNIT-2).pptx
Pf cs102 programming-10 [structs]
A10presentationofbiologyandpshyology.pptx
Structures and Pointers
Ad

More from Shakila Mahjabin (15)

PPTX
Computer processing
PPTX
Arrays in CPP
DOCX
CSC 433 Sample normalization SQL Question
PPT
SQL : introduction
PPT
Normalization
PDF
Solution of Erds
PPT
Entity Relationship Diagram
PPT
Ch1- Introduction to dbms
PPTX
Stack and queue
PPTX
Algo analysis
PPTX
Merge sort and quick sort
PDF
PDF
array, function, pointer, pattern matching
PDF
String operation
PDF
Data Structure Basics
Computer processing
Arrays in CPP
CSC 433 Sample normalization SQL Question
SQL : introduction
Normalization
Solution of Erds
Entity Relationship Diagram
Ch1- Introduction to dbms
Stack and queue
Algo analysis
Merge sort and quick sort
array, function, pointer, pattern matching
String operation
Data Structure Basics
Ad

Recently uploaded (20)

PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Classroom Observation Tools for Teachers
PPTX
Cell Structure & Organelles in detailed.
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
Basic Mud Logging Guide for educational purpose
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
RMMM.pdf make it easy to upload and study
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Pharma ospi slides which help in ospi learning
PDF
01-Introduction-to-Information-Management.pdf
PDF
Business Ethics Teaching Materials for college
O5-L3 Freight Transport Ops (International) V1.pdf
O7-L3 Supply Chain Operations - ICLT Program
Classroom Observation Tools for Teachers
Cell Structure & Organelles in detailed.
2.FourierTransform-ShortQuestionswithAnswers.pdf
Complications of Minimal Access Surgery at WLH
Basic Mud Logging Guide for educational purpose
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Abdominal Access Techniques with Prof. Dr. R K Mishra
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Week 4 Term 3 Study Techniques revisited.pptx
Final Presentation General Medicine 03-08-2024.pptx
RMMM.pdf make it easy to upload and study
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Renaissance Architecture: A Journey from Faith to Humanism
Anesthesia in Laparoscopic Surgery in India
Pharma ospi slides which help in ospi learning
01-Introduction-to-Information-Management.pdf
Business Ethics Teaching Materials for college

Codes on structures

  • 1. 1. #include <iostream.h> #include <conio.h> #include <iomanip.h> struct student { int ID; // 4 bytes char name[10];//10bytes float grade; // 4bytes int age; // 4 char phone[10]; // 10 char e_mail[16]; // 16 }; void display(struct student s) { cout<<setw(3)<< s.ID <<setw(12)<< s.name <<setw(8)<< setiosflags (ios::showpoint)<<setprecision(2)<< s.grade<<setw(5)<<s.age <<setw(10)<< s.phone<< setw(18)<<s.e_mail<<endl; } void main() { struct student s1={55,"Amir Ali",3.5f,23,"6535418","amir@yahoo.com"}; struct student s2={26,"Mujahid",2.9888f,25,"5362169", "muj@hotmail.com"}; struct student s3={39,"M Jamil",3.108f,30,"2345677","jam@hotmail.com"}; struct student s4={44,"Dilawar",2.7866f,31,"5432186","dil@hotmail.com"}; struct student s5={59,"S.Naveed",2.9f,27,"2345671","navee@yahoo.com"}; cout<<" Students Records Sheetn"; cout<<" ~~~~~~~~~~~~~~~~~~~~~~nn"; cout<<"ID# NAME GRADE AGE PHONE E-MAILn"; cout<<"~~~ ~~~~ ~~~~~ ~~~ ~~~~~ ~~~~~~~n"; display(s1); // structure pass to function display(s2); // structure pass to function display(s3); display(s4); display(s5); } 2. // In this program you will see the structures (members Manipulation), // Passing structures to functions: #include <iostream.h> #include <iomanip.h> struct S_Details { char name [30];
  • 2. int exam1; int exam2; int exam3; int final; float sem_ave; char letter_grade; }; //inputs the data items for a student, structure //is passed by reference struct S_Details get_stu ( ) { struct STU_GRADES student; cout << "nnnn Enter the information for a studentn"; cout << " Name: "; cin.getline (student.name, 30, 'n'); cout << " Exam1: "; cin >> student.exam1; cout << " Exam2: "; cin >> student.exam2; cout << "exam3: "; cin >> student.exam3; cout << "final: "; cin >> student.final; return student; } //displays a student's info. //structure is passed by value void print_stu (struct STU_GRADES stu) { cout << "nnnGrade report for: " << stu.name<<endl; cout << "nexam 1texam 2texam 3tfinaln"; cout << stu.exam1 << "t" << stu.exam2 << "t"<< stu.exam3 << "t" << stu.final; cout << "nnnsemester average: " << setiosflags (ios::fixed)<< setprecision (2) << stu.sem_ave; cout << "nsemester grade: " << stu.letter_grade; } float calc_ave (int ex1, int ex2, int ex3, int final) { float ave; ave = float (ex1 + ex2 + ex3 + final)/4.0f; return ave; } char assign_let (float average) {
  • 3. char let_grade; if (average >=90) let_grade = 'A'; else if (average >= 80) let_grade = 'B'; else if (average >= 70) let_grade = 'C'; else if (average >= 60) let_grade = 'D'; else let_grade = 'F'; return let_grade; } int main() { struct S_Details stu; char more; do { //pass the entire structure Stu = get_stu ( ); //pass elements of the strucutre stu.sem_ave = calc_ave (stu.exam1, stu.exam2, stu.exam3, stu.final); //pass elements of the structure stu.letter_grade = assign_let (stu.sem_ave); //pass the entire structure print_stu (stu); cout << "nnn Enter another student? (y/n) "; cin >> more; //grab the carriage return since //character data is input next cin.ignore ( ); } while (more == 'y' || more == 'Y'); return 0; }