1
2#include <iostream>
3using namespace std;
4
5int main() {
6 int number;
7
8 cout << "Enter an integer: ";
9 cin >> number;
10
11 cout << "You entered " << number;
12 return 0;
13}
1
2#include<iostream>
3#include<fstream>
4using namespace std;
5
6struct mail
7{
8 char un[50]; // user name
9 char pd[50]; // passsword
10 void reg(int);
11} obj[5];
12
13void mail::reg(int k)
14{
15 int i=k;
16 cout<<"\nEnter user name :: ";
17 cin>>un;
18 cout<<"\nEnter password :: ";
19 cin>>pd;
20
21 ofstream filout;
22 filout.open("C:\\Users\\acer\\Documents\\registration.txt",ios::app|ios::binary);
23 if(!filout)
24 {
25 cout<<"\nCannot open file\n";
26 }
27 else
28 {
29 cout<<"\n";
30 filout.write((char *)&obj[i],sizeof(mail));
31 filout.close();
32 }
33
34 cout<<"\n...........You are now registered.......... \n\n";
35
36} // end of sign up or register func
37
38int main()
39{
40 int t;
41 cout<<"\nEnter Registration Details for User 1 :: \n";
42 obj[0].reg(0);
43 cout<<"\nEnter Registration Details for User 2 :: \n";
44 obj[1].reg(1);
45 cout<<"\nEnter Registration Details for User 3 :: \n";
46 obj[2].reg(2);
47
48 mail obj2;
49
50 ifstream filein;
51 filein.open("C:\\Users\\acer\\Documents\\registration.txt",ios::in|ios::binary);
52 if(!filein)
53 {
54 cout<<"\nUnable to open file to read\n";
55 }
56 else
57 {
58 cout<<"\nRegistered Details of All Users :: \n";
59 filein.read((char *)&obj2,sizeof(obj2));
60 while(filein)
61 {
62 cout<<"\nUsername :: "<<obj2.un<<"\nPasswword :: "<<obj2.pd<<"\n";
63 filein.read((char *)&obj2,sizeof(obj2));
64 }
65 //filein.close();
66 }
67 return 0;
68}
69}
70
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
1#include <iostream>
2#include <fstream>
3
4using namespace std;
5
6#define FILENAME "data.bin"
7
8void what_action();
9
10void register_menu();
11void login_menu();
12
13void add_user(string username, string password);
14bool check_user(string username, string password);
15
16int main()
17{
18 what_action();
19}
20
21void what_action()
22{
23 short int input;
24
25 cout << "1. Login\n2. Register" << endl;
26 cin >> input;
27
28 switch(input)
29 {
30 case 1:
31 login_menu();
32 break;
33
34 case 2:
35 register_menu();
36 break;
37
38 default:
39 cout << "Type Again!" << endl;;
40 what_action();
41 break;
42 }
43}
44
45void register_menu()
46{
47 string user, pw;
48 int agree;
49
50 cout << "Username: ";
51 cin >> user;
52
53 cout << "Password: ";
54 cin >> pw;
55
56 cout << "Have You Read our Agreement ? ( 1 = yes )";
57 cin >> agree;
58
59 switch(agree)
60 {
61 case 1:
62 add_user(user, pw);
63 break;
64
65 default:
66 cout << "Please Read our Agreement First !" << endl;
67 register_menu();
68 break;
69 }
70}
71
72void login_menu()
73{
74 string user, pw;
75
76 cout << "Username: ";
77 cin >> user;
78
79 cout << "Password: ";
80 cin >> pw;
81
82 if(check_user(user, pw) == true)
83 cout << "you have logged in succefully !" << endl;
84 else
85 cout << "Data is Wrong!" << endl;
86}
87
88void add_user(string username, string password)
89{
90 ofstream file;
91 file.open(FILENAME, ios_base::app);
92
93 file << username << "\n";
94 file << password << "\n";
95
96 file.close();
97}
98
99bool check_user(string username, string password)
100{
101 ifstream file;
102
103 string line;
104 bool what_to_return;
105
106 file.open(FILENAME, ios_base::binary);
107
108 if(file.is_open())
109 {
110 while(getline(file, line))
111 {
112 string usr, pw;
113
114 usr = line;
115
116 getline(file,line);
117
118 pw = line;
119
120 if(usr == username && password == pw)
121 {
122 what_to_return = true;
123 break;
124 }
125 else
126 what_to_return = false;
127 }
128 }
129
130 return what_to_return;
131}