Google PlusFacebookTwitter

Structures – Student Data

By on Mar 27, 2007 in On A Whim | 0 comments

Share On GoogleShare On FacebookShare On Twitter

/* 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



Submit a Comment

Your email address will not be published. Required fields are marked *