Categories
Uncategorised

Classes – Student

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

/ Classes – Program to manage student data /

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

class student
{
int admno;
char sname[20];
float mark[5], total;
float calculate();
public:
void takedata();
void showdata();
} stud;

float avg;

void student :: takedata()
{
cout<<endl<<“Enter admission number : “;
cin>>admno;
cout<<“Enter student name : “;
gets(sname);
cout<<“Enter marks in five subjects”<<endl;
for (int i = 0; i < 5; i++)
{
cout<<“Enter marks for subject “<<i + 1<<” : “;
cin>>mark[i];
}
avg = calculate();
showdata();
}

void student :: showdata()
{
cout<<endl<<“Details for student are”<<endl
<<“Student admission number : “<<admno<<endl
<<“Student name : “<<sname<<endl
<<“Student marks in five subjects”;
for (int i = 0; i < 5; i++)
cout<<endl<<“Marks of student in subject “<<i + 1
<<” : “<<mark[i];
cout<<endl<<“Total marks of student : “<<total<<endl
<<“Average marks of student : “<<avg<<endl;
}

float student :: calculate()
{
total = 0;
for (int i = 0; i < 5; i++)
total+= mark[i];
return (total / 5);
}

void main()
{
clrscr();
cout<<“Enter details for student”;
stud.takedata();
getch();
}

/ Output */

Enter details for student
Enter admission number : 42
Enter student name : Arthur Dent
Enter marks in five subjects
Enter marks for subject 1 : 58
Enter marks for subject 2 : 98
Enter marks for subject 3 : 67
Enter marks for subject 4 : 53
Enter marks for subject 5 : 42

Details for student are
Student admission number : 42
Student name : Arthur Dent
Student marks in five subjects
Marks of student in subject 1 : 58
Marks of student in subject 2 : 98
Marks of student in subject 3 : 67
Marks of student in subject 4 : 53
Marks of student in subject 5 : 42
Total marks of student : 318
Average marks of student : 63.6

Categories
Uncategorised

Classes – My Folder

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

/ Classes – My Folder /

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

class myfolder
{
char filename[10][25];
long totspace, usedspace, avspace;
public:
void newentry();
void
showfiles();
long retspace()
{
avspace = (totspace – usedspace) / 1000;
return avspace;
}
} file;

void myfolder :: newentry()
{
for (int i=0; i<10; i++)
{
cout<<“Enter filename for file number “<<i+1<<” : “;
gets(filename[i]);
}
do
{
cout<<“Enter total space allocated in bytes : “;
cin>>totspace;
cout<<“Enter used space in bytes : “;
cin>>usedspace;
if (totspace < usedspace)
cout<<“Total space cannot be less than used space. “
<<“Please enter again”<<endl;
} while (totspace < usedspace);
}

void myfolder :: showfiles()
{
for (int i=0; i<10; i++)
cout<<endl<<“Filename for file number “<<i+1<<” is : “
<<filename[i];
cout<<endl<<“Total space allocated in bytes is “
<<totspace<<endl
<<“Used space in bytes is “<<usedspace;
}

void main()
{
clrscr();
long res;
cout<<“Enter data for files”<<endl;
file.newentry();
cout<<endl<<“Displaying data for files”;file.showfiles();
res = file.retspace();
cout<<endl<<“Total available space in kilobytes is “
<<res<<endl;
getch();
}

/ Output */

Enter data for files
Enter filename for file number 1 : Hitchhiker’s
Enter total space allocated in bytes : 2356565
Enter used space in bytes : 1234547

Displaying data for files
Filename for file number 1 is Hitchhiker’s
Total space allocated in bytes is 2356565
Used space in bytes is 1234547
Total available space in kilobytes is 1122.018