1int fib(int n) {
2if (n==0)
3 return 0;
4else if (n == 1)
5 return 1;
6else
7 return fib(n−1) + fib(n−2);
8}
9
1
2
3#include<iostream>
4#include<fstream>
5using namespace std;
6
7struct mail
8{
9 char un[50]; // user name
10 char pd[50]; // passsword
11 void reg(int);
12} obj[5];
13
14void mail::reg(int k)
15{
16 int i=k;
17 cout<<"\nEnter user name :: ";
18 cin>>un;
19 cout<<"\nEnter password :: ";
20 cin>>pd;
21
22 ofstream filout;
23 filout.open("C:\\Users\\acer\\Documents\\registration.txt",ios::app|ios::binary);
24 if(!filout)
25 {
26 cout<<"\nCannot open file\n";
27 }
28 else
29 {
30 cout<<"\n";
31 filout.write((char *)&obj[i],sizeof(mail));
32 filout.close();
33 }
34
35 cout<<"\n...........You are now registered.......... \n\n";
36
37} // end of sign up or register func
38
39int main()
40{
41 int t;
42 cout<<"\nEnter Registration Details for User 1 :: \n";
43 obj[0].reg(0);
44 cout<<"\nEnter Registration Details for User 2 :: \n";
45 obj[1].reg(1);
46 cout<<"\nEnter Registration Details for User 3 :: \n";
47 obj[2].reg(2);
48
49 mail obj2;
50
51 ifstream filein;
52 filein.open("C:\\Users\\acer\\Documents\\registration.txt",ios::in|ios::binary);
53 if(!filein)
54 {
55 cout<<"\nUnable to open file to read\n";
56 }
57 else
58 {
59 cout<<"\nRegistered Details of All Users :: \n";
60 filein.read((char *)&obj2,sizeof(obj2));
61 while(filein)
62 {
63 cout<<"\nUsername :: "<<obj2.un<<"\nPasswword :: "<<obj2.pd<<"\n";
64 filein.read((char *)&obj2,sizeof(obj2));
65 }
66 //filein.close();
67 }
68 return 0;
69}
70