Categories
Uncategorised

Classes – Country Data

/* Copyright © 2007 Ankur Banerjee. Special thanks to Naman Bagga for source code verification. 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 country data /

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

int i, flag;

class country
{
char name[50], capital[50];
public:
class president
{
public:
char fname[20], lname[20];
} pres;
void getdata()
{
cout<<endl<<“Enter data for country “<<i + 1<<endl
<<“Enter name : “;
gets(name);
cout<<“Enter capital : “;
gets(capital);
cout<<“Enter name of president (first name, then last name) : “;
cin>>pres.fname>>pres.lname;
}
void showdata()
{
cout<<endl<<“Displaying data for country “
<<i + 1<<endl
<<“Country name : “<<name<<endl
<<“Capital : “<<capital<<endl
<<“President : “<<pres.fname<<” “
<<pres.lname<<endl;
}
int search(char check[50])
{
if (strcmp (name, check) == 0)
{
cout<<endl<<“Displaying data for country “
<<check<<endl
<<“Capital : “<<capital<<endl
<<“President : “<<pres.fname<<“
“<<pres.lname<<endl;
flag = 1;
}
return flag;
}
} c[5];

void main()
{
clrscr();
int ch, f;
char choice, n[50];
cout<<endl<<“Country Data Management Program”
<<endl<<“Enter initial data for 5 countries”<<endl;
for (i = 0; i < 5; i++)
c[i].getdata();
do
{
cout<<endl<<“Program Menu”<<endl
<<“1. Display information about all countries”<<endl
<<“2. Search for country data by name”<<endl
<<“Enter your choice : “;
cin>>ch;
if (ch == 1)
{
cout<<endl<<“Displaying data for all countries”<<endl;
for (i = 0; i < 5; i++)
c[i].showdata();
}
else if (ch == 2)
{
cout<<endl<<“Enter country name to search for : “;
gets(n);
flag = f = 0;
for(i = 0; i < 5; i++)
{
f = c[i].search(n);
if (f != 0)
break;
}
if (f == 0)
cout<<“Country you requested is not present in records”;
}
else cout<<endl<<“You entered an incorrect choice”;
cout<<endl<<“Do you wish to continue – y / n : “;
cin>>choice;
} while (choice == ‘y’ || choice == ‘Y’);
cout<<endl;
getch();
}

/ Output */

Country Data Management Program
Enter initial data for 5 countries

Enter data for country 1
Enter name : India
Enter capital : New Delhi
Enter name of president (first name, then last name) : APJ Kalam

Program Menu
1. Display information about all countries
2. Search for country data by name
Enter your choice : 1

Displaying data for all countries
Displaying data for country 1
Country name : India
Capital : New Delhi
President : APJ Kalam

Do you wish to continue – y / n : y

Program Menu
1. Display information about all countries
2. Search for country data by name
Enter your choice : 2

Enter country name to search for : India

Displaying data for country India
Capital : New Delhi
President : APJ Kalam

Categories
Uncategorised

Classes – Floppy Box

/* Copyright © 2007 Ankur Banerjee. Special thanks to Naman Bagga for source code verification. 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 – Floppy box /

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

int i;

class floppybox
{
int size;
char name[20];
public:
void getdata()
{
cout<<endl<<“Enter data for floppy “<<i + 1<<endl
<<“Enter name of floppy : “;
gets(name);
cout<<“Enter size of floppy in MB : “;
cin>>size;
}
void showdata()
{
cout<<endl<<“Displaying data for floppy “<<i + 1<<endl
<<“Floppy name : “<<name<<endl
<<“Floppy size in MB : “<<size<<endl;
}
int findsize(char check[20])
{
if (strcmp (check, name) == 0)
return size;
else return 0;
}
} floppy[5];

void main()
{
clrscr();
int ch, s;
char n[20], choice;
cout<<“Floppy Box Program\n\n”
<<“Enter initial data for all floppies”<<endl;
for (i = 0; i < 5; i++)
floppy[i].getdata();
do
{
cout<<endl<<“Program Menu”<<endl
<<“1. Display information about all floppies”<<endl
<<“2. Search floppy size by name”<<endl
<<“Enter your choice : “;
cin>>ch;
if (ch == 1)
{
cout<<endl<<“Displaying data for all floppies”<<endl;
for (i = 0; i < 5; i++)
floppy[i].showdata();
}
else if (ch == 2)
{
cout<<endl<<“Enter floppy name to search for : “;
gets(n);
for(i = 0; i < 5; i++)
{
s = floppy[i].findsize(n);
if (s != 0)
break;
}
if (s == 0)
cout<<“Floppy name you requested is not present in records”;
else cout<<“Size of floppy with name “<<n
<<” is “<<s<<” MB”;
}
else cout<<endl<<“You entered an incorrect choice”;
cout<<endl<<“Do you wish to continue – y / n : “;
cin>>choice;
} while (choice == ‘y’ || choice == ‘Y’);
cout<<endl;
getch();
}

/ Output */

Floppy Box Program

Enter initial data for all floppies

Enter data for floppy 1
Enter name of floppy : Moser Baer
Enter size of floppy in MB : 2

Program Menu
1. Display information about all floppies
2. Search floppy size by name
Enter your choice : 1

Displaying data for all floppies

Displaying data for floppy 1
Floppy name : Moser Baer
Floppy size in MB : 2

Do you wish to continue – y / n : y

Program Menu
1. Display information about all floppies
2. Search floppy size by name
Enter your choice : 2

Enter floppy name to search for : Moser Baer
Size of floppy with name Moser Baer is 2 MB