Categories
Uncategorised

Structures – Student Data

/* Copyright © 2007 Ankur Banerjee. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. http://www.fsf.org/licensing/licenses/lgpl.html /

/ Structures – Managing student data /

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <iomanip.h>

struct date
{
int dd, mm, yy;
};

struct points
{
int sub1, sub2, sub3;
float avg;
};

struct student
{
int rno;
char name[50], stream[50];
date dob;
points marks;
} s[10], stud[10];

int average (student s[10])
{
int flag = 0;
cout<<endl<<“Displaying student data”<<endl;
for (int i=0; i<10; i++)
{
cout<<endl<<“Data for student number “<<i+1<<endl;
cout<<“Student roll number : “<<setw(50)<<s[i].rno<<endl;
cout<<“Student name : “<<setw(50)<<s[i].name<<endl;
cout<<“Student date of birth : “<<setw(50)<<s[i].dob.dd<<” “
<<s[i].dob.mm<<“ “<<s[i].dob.yy<<endl;
cout<<“Student stream : “<<setw(50)<<s[i].stream<<endl;
cout<<“Student marks in subject 1”<<setw(50)<<s[i].marks.sub1<<endl;
cout<<“Student marks in subject 2”<<setw(50)<<s[i].marks.sub2<<endl;
cout<<“Student marks in subject 3”<<setw(50)<<s[i].marks.sub3<<endl;
s[i].marks.avg = (s[i].marks.sub1 + s[i].marks.sub2 + s[i].marks.sub3)/3;
cout<<“Average marks of student in 3 subjects : “<<setw(50)
<<s[i].marks.avg<<endl;
if (s[i].marks.avg < 120)
flag++;
}
return flag;
}

void studstream (student s[10])
{
int j=1;
char find[50];
cout<<endl<<“Enter stream to be searched for : “;
gets(find);
cout<<endl<<“Displaying data for students of requested stream”<<endl;
for (int i=0; i<10; i++)
{
if (strcmp (s[i].stream, find) == 1)
{
cout<<endl<<“Data of student “<<j<<” meeting required criteria”<<endl;
cout<<“Student roll number : “<<setw(50)<<s[i].rno<<endl;
cout<<“Student name : “<<setw(50)<<s[i].name<<endl;
cout<<“Student date of birth : “<<setw(50)<<s[i].dob.dd<<“
<<s[i].dob.mm<<“ “<<s[i].dob.yy<<endl;
cout<<“Student stream : “<<setw(50)<<s[i].stream<<endl;
cout<<“Student marks in subject 1 : “<<setw(50)<<s[i].marks.sub1<<endl;
cout<<“Student marks in subject 2 : “<<setw(50)<<s[i]
.marks.sub2<<endl;

cout<<“Student marks in subject 3 : “<<setw(50)<<s[i].marks.sub3<<endl;
s[i].marks.avg = (s[i].marks.sub1 + s[i].marks.sub2 + s[i].marks.sub3)/3;
cout<<“Average marks of student in 3 subjects : “
<<setw(50)<<s[i].marks.avg<<endl;
j++;
}
}
}

void studdob (student s[10])
{
int j=1;
date find;
cout<<endl<<“Enter date of birth to search for in DD MM YYYY format : “;
cin>>find.dd>>find.mm>>find.yy;
cout<<endl<<“Displaying data for students of requested date of birth”<<endl;
for (int i=0; i<10; i++)
{
if ((s[i].dob.dd == find.dd) && (s[i].dob.mm == find.mm) && (s[i].dob.yy == find.yy))
{
cout<<endl<<“Data of student “<<j<<” meeting required criteria”<<endl;
cout<<“Student roll number : “<<setw(50)<<s[i].rno<<endl;
cout<<“Student name : “<<setw(50)<<s[i].name<<endl;
cout<<“Student date of birth : “<<setw(50)<<s[i].dob.dd<<“ <<s[i].dob.mm<<“ “<<s[i].dob.yy<<endl;
cout<<“Student stream : “<<setw(50)<<s[i].stream<<endl;
cout<<“Student marks in subject 1 : “<<setw(50)<<s[i].marks.sub1<<endl;
cout<<“Student marks in subject 2 : “<<setw(50)<<s[i].marks.sub2<<endl;
cout<<“Student marks in subject 3 :”<<setw(50)<<s[i].marks.sub3<<endl;
s[i].marks.avg = (s[i].marks.sub1 + s[i].marks.sub2 + s[i].marks.sub3)/3;
cout<<“Average marks of student in 3 subjects : “ <<setw(50)<<s[i].marks.avg<<endl;
j++;
}
}
}

void main()
{
clrscr();
cout<<“Creating database for 10 students”<<endl;
for (int i=0; i<10; i++)
{
cout<<endl<<“Enter data for student “<<i+1<<endl<<“Enter student
roll number : “;
cin>>stud[i].rno;
cout<<“Enter student name : “;
gets(stud[i].name);
cout<<“Enter student date of birth in DD MM YYYY format : “;
cin>>stud[i].dob.dd>>stud[i].dob.mm>>stud[i].dob.yy;
cout<<“Enter student stream : “;
gets(stud[i].stream);
cout<<“Enter student marks in subject 1 : “;
cin>>stud[i].marks.sub1;
cout<<“Enter student marks in subject 2 : “;
cin>>stud[i].marks.sub2;
cout<<“Enter student marks in subject 3 : “;
cin>>stud[i].marks.sub3;
}
int ch;
cout<<endl<<“Program Menu”<<endl
<<“1. Calculate average marks for each student and print student details”
<<endl<<“2. Search by stream”<<endl<<“3. Search by date of birth”
<<endl<<“Enter your choice : “;
cin>>ch;
switch (ch)
{
case 1 : int fail;
fail = average (stud);
cout<<endl<<“Number of students failed is “<<fail;
break;
case 2 : studstream (stud);
break;
case 3 : studdob (stud);
break;
default : cout<<endl<<“You entered an incorrect choice”;
}
cout<<endl;
getch();
}

/ Output */

Creating database for 10 students

Enter data for student 1
Enter student roll number : 42
Enter student name : Arthur Dent
Enter student date of birth in DD MM YYYY format : 20
7
1990
Enter student stream : Science
Enter student marks in subject 1 : 85
Enter student marks in subject 2 : 87
Enter student marks in subject 3 : 86

Program Menu
1. Calculate average marks for each student and print student details
2. Search by stream
3. Search by date of birth
Enter your choice : 1

Displaying student data

Data for student number 1
Student roll number : 42
Student name : Arthur Dent
Student date of birth : 20 7 1990
Student stream : Science
Student marks in subject 1 : 85
Student marks in subject 2 : 87
Student marks in subject 3 : 86
Average marks of student in 3 subjects : 86

Number of students failed is 2

Program Menu
1. Calculate average marks for each student and print student details
2. Search by stream
3. Search by date of birth
Enter your choice : 2

Enter stream to be searched for : Science

Displaying data for students of requested stream

Data of student 1 meeting required criteria

Student roll number : 42
Student name : Arthur Dent
Student date of birth : 20 7 1990
Student stream : Science
Student marks in subject 1 : 85
Student marks in subject 2 : 87
Student marks in subject 3 : 86
Average marks of student in 3 subjects : 86

Program Menu
1. Calculate average marks for each student and print student details
2. Search by stream
3. Search by date of birth
Enter your choice : 3

Enter date of birth to search for in DD MM YYYY format : 20 7 1990

Displaying data for students of requested date of birth

Data of student 1 meeting required criteria

Student roll number : 42
Student name : Arthur Dent
Student date of birth : 20 7 1990
Student stream : Science
Student marks in subject 1 : 85
Student marks in subject 2 : 87
Student marks in subject 3 : 86
Average marks of student in 3 subjects : 86

Categories
Uncategorised

Structures – Person Data

/ Copyright (C) 2007 Ankur Banerjee. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. http://www.fsf.org/licensing/licenses/lgpl.html */

/ Structures – Program to manage person data /

#include <iostream.h>
#include <conio.h>
#include
<stdio.h>
#include <string.h>

struct person
{
int id, age;
char name[50], add[100], nat[50];
} p[20], per[20];

void print (person p[20])
{
int j=1;
cout<<endl<<“Details of people allowed to vote in India”<<endl;
for (int i=0; i<20; i++)
{
if ((p[i].age >= 18) && (strcmp (p[i].nat, “Indian”) == 0))
{
cout<<endl<<“Details for person number “<<j<<” eligible to vote”<<endl<<“Person ID : “<<p[i].id<<endl<<“Person name : “;
puts(p[i].name);
cout<<“Person address : “;
puts(p[i].add);
cout<<“Person age : “<<p[i].age<<endl<<“Person nationality : “;
puts(p[i].nat);
j++;
}
}
}

int search (person p[20], int id)
{
int flag;
for (int i=0; i<20; i++)
if (p[i].id == id)
{
flag = 1;
break;
}
if (flag == 1)
return 1;
else return 0;
}

void arrange (person p[20])
{
person temp[20];
int max, pos;
for (int i=0; i<=18; i++)
{
max = p[i].id;
pos = i;
for (int j=i+1; j<20; j++)
{
if (p[i].id > max)
{
max = p[i].id;
pos = j;
}
}
temp[i] = p[i];
p[i] = p[pos];
p[pos] = temp[i];
}
cout<<endl<<“Person data in descending order of Person ID”<<endl;
for (int k=0; k<20; k++)
{
cout<<endl<<“Data for person “<<k+1<<endl<<“Person ID : “
<<p[k].id<<endl<<“Person name : “;
puts(p[k].name);
cout<<“Person address : “;
puts(p[k].add);
cout<<“Person age : “<<p[k].age<<endl<<“Person nationality : “;
puts(p[k].nat);
}
}

void main()
{
clrscr();
int ch, id, ans;
cout<<endl<<“Program to manage person data”<<endl;
for (int i=0; i<20; i++)
{
cout<<endl<<“Enter data for person “<<i+1<<endl<<“Enter person ID : “;
cin>>per[i].id;
cout<<“Enter person name : “;
gets(per[i].name);
cout<<“Enter person address : “;
gets(per[i].add);
cout<<“Enter person age : “;
cin>>per[i].age;
cout<<“Enter person nationality : “;
gets(per[i].nat);
cout<<endl;
}
cout<<endl<<“Operation Menu”<<endl
<<“1. Print record of all people allowed to
vote in India”<<endl
<<“2. Search for a record using Person ID”<<endl
<<“3. Arrange all records in descending order of ID”<<endl
<<“Enter your choice : “;
cin>>ch;
switch (ch)
{
case 1: print (per);
break;
case 2 : cout<<“Enter the person ID to be searched : “;
cin>>id;
int ans;
ans = search (per, id);
if (ans == 1)
cout<<“The ID you searched for is present”;
else cout<<“The ID you searched for is not present”;
break;
case 3: arrange (per);
break;
default : cout<<endl<<“You entered an incorrect choice”<<endl;
}
getch();
}

/ Output */

Program to manage person data

Enter data for person 1
Enter person ID : 42
Enter person name : Arthur Dent
Enter person address : 42, Guide Road, New Delhi 110042
Enter person age : 42
Enter person nationality : Indian

Operation Menu

1. Print record of all people allowed to vote in India
2. Search for a record using ID
3. Arrange all records in descending order of ID
Enter your choice : 1

Details of people allowed to vote in India

Details for person number 1 eligible to vote
Person ID : 42
Person name : Arthur Dent
Person address : 42, Guide Road, New Delhi 110042
Person age : 42
Person nationality : Indian

Operation Menu

1. Print record of all people allowed to vote in India
2. Search for a record using ID
3. Arrange all records in descending order of ID
Enter your choice : 2

Enter the person ID to be searched : 42
The ID you searched for is present

Operation Menu

1. Print record of all people allowed to vote in India
2. Search for a record using ID
3. Arrange all records in descending order of ID
Enter your choice : 3

Person data in descending order of Person ID

Data for person 1

Person ID : 42
Person name : Arthur Dent
Person address : 42, Guide Road, New Delhi 110042
Person age : 42

Person nationality : Indian

Data for person 2

Person ID : 41
Person name : Douglas Adams
Person address : 41, Guide Road, New Delhi 110042
Person age : 42
Person nationality : Indian