سلام
برنامه اي كه در زير اومده يه برنامه اي هست كه هدفش مواظبت از يه اطلاعاتي(به صورت فايل تكست) هست ولي نكته مهم و بيشتر حجم اين برنامه صرف چگونگي مواظبت از اين اطلاعات هست(با گذاشتن پسورد).
مي خواستم شما دوستان اگه نظري در مورد بهتر شدن برنامه و يا راه حل بهتري دارين بهم بگين.(در ضمن اگه مشكلي هم داره بگيد)
ممنونم:11:
کد:#include <iostream>
#include <string>
#include <fstream>
#define EVER ;;
using namespace std;
void passFunc();
void changPass();
void newInfo();
void info();
int main()
{
int choice;
char ch;
cout <<"*******LOADING...********\n";
cout <<"Do you want to change your password?(y/n):";
cin.get(ch);
if(ch == 'y')
changPass();
else
passFunc();
cout <<"\n(1)newinfo(2)info(0 to quit):";
cin>>choice;
switch(choice)
{
case 1: newInfo(); break;
case 2: info(); break;
default: return NULL;
}
return 0;
}
void passFunc()
{
string pass1,pass2,pass;
int test;
ofstream gFile("F:\\test.txt",ios::app);
gFile.close();
ifstream tFile("F:\\test.txt");
if(!tFile)
{
cout <<"\nfile not opened...\n";
}
string ch;
tFile>>ch;
if(ch.empty())
test = 0;
else
test = 1;
tFile.close();
for(EVER)
{
if(!test)
{
cout <<"Go to make a password--->\n";
cout <<"Enter a password:";
cin>>pass1;
cin.ignore();
cout <<"\nEnter password again:";
cin>>pass2;
cin.ignore();
gFile.open("F:\\test.txt");
gFile <<"1";
gFile.close();
if(pass1 != pass2)
{
cout <<"\nthe passwords are diffrent.\n";
gFile.open("F:\\test.txt");
gFile.clear();
gFile.close();
continue;
}
ofstream fout("F:\\pass.txt");
if(!fout)
{
cout <<"file not opened...\n";
break;
}
fout <<pass1;
fout.close();
gFile.open("F:\\test.txt");
gFile <<"1";
gFile.close();
break;
}//End of orginal if
else
{
string StrTest;
cout <<"\nEnter pass:";
cin>>pass;
cin.ignore();
ifstream fin("F:\\pass.txt");
if(!fin)
{
cout <<"\nfile not opened...\n";
break;
}
fin>>StrTest;
fin.ignore();
fin.close();
if(StrTest != pass)
{
cout <<"\nThis password is wrong...\n";
continue;
}
break;
}
}//End of for
}//End of func
void changPass()
{
string back,next,test,file,ch;
int bTest;
ifstream chang("F:\\test.txt");
if(!chang)
{
cout <<"\nfile not opened...\n";
}
chang>>ch;
if(ch.empty())
bTest = 0;
else
bTest = 1;
chang.close();
for(EVER)
{
if(bTest)
{
cout <<"Enter back pass:";
cin>>back;
cin.ignore();
ifstream fin("F:\\pass.txt");
if(!fin)
{
cout <<"\nfile not opened...\n";
break;
}
fin>>file;
fin.ignore();
fin.close();
if(back != file)
{
cout <<"\nThis is wrong...\n";
continue;
}
cout <<"Enter new pass:";
cin>>next;
cin.ignore();
cout <<"\nEnter new pass again:";
cin>>test;
cin.ignore();
if(next != test)
{
cout <<"\nThe passwords are diffrent.\n";
continue;
}
ofstream fout("F:\\pass.txt");
if(!fout)
{
cout <<"file not opened...\n";
break;
}
fout <<next;
break;
fout.close();
}
else
{
cout <<"you dont have any password\nAre you ok?!@!";
cout <<"plz make a pssword later...\n";
break;
}
}//End of for
}//End of Func
void newInfo()
{
ofstream fNew("F:\\info.txt",ios::app);
if(!fNew)
{
cout <<"\nFile not opened...\n";
}
string NewInfo;
cout <<"\nEnter new info:";
cin>>NewInfo;
cin.ignore();
fNew <<NewInfo<<endl;
fNew.close();
}
void info()
{
ifstream fInfo("F:\\info.txt");
if(!fInfo)
{
cout <<"\nFile not opened...\n";
}
char ch;
while(fInfo.get(ch))
cout <<ch;
cout <<endl;
fInfo.close();
}