-
Notifications
You must be signed in to change notification settings - Fork 0
/
27.cpp
63 lines (46 loc) · 1.22 KB
/
27.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
@Author: Amritanshu Sikdar
Session: 2018-'19
Repository: https://github.com/amritanshusikdar/CS30PracticalQuestion
*/
// Quiz ---- Countries & their Capitals
#include<conio.h>
#include<stdio.h>
#include<fstream.h>
#include<string.h>
struct quiz
{
char name[20], capital[20];
};
void main()
{
clrscr();
int i, found=0;
char name[20];
quiz country;
fstream file("QUIZ.DBF", ios::in | ios::out | ios::binary);
cout << "Enter country & its capital:-\n";
for(i=0; i<5; i++)
{
cout << "Country " << i+1 << ": \n";
cout << "Name: ";
gets(country.name);
cout << "Capital: ";
gets(country.capital);
file.write((char*) &country, sizeof(country));
}
cout << "Enter name of country you want to know capital of: ";
gets(name);
file.seekg(0,ios::beg);
while(!file.eof() && found == 0)
{
file.read((char*) &country, sizeof(country));
if(!strcmpi(name,country.name))
found = 1;
}
if(found)
cout << "Capital: " << country.capital << endl;
else cout << "Country not in database!";
file.close();
getch();
}