Post: [C++] Is This a good Place to learn C++?
02-06-2011, 04:56 PM #1
Girby2K11
☮ ☯ ☢ ✔ ➝
(adsbygoogle = window.adsbygoogle || []).push({}); over the last month i have been reading this website and book.
the website is called You must login or register to view this content.

and i am reading this book called c++ for dummies by Stephan R. Davies

i am at the start of the book and website but i was wondering is it a good place to understand all the coding of c++ and be able to write full gui's?
03-01-2011, 09:02 PM #20
x-MaGiiKZz-o
Who’s Jim Erased?
I've ordered C++ for dummies and C++ for absoloute beginners as I am a noob in C++, however I can do HTML well.
03-02-2011, 05:34 PM #21
Girby2K11
☮ ☯ ☢ ✔ ➝
Originally posted by TheUberFail View Post
    

#include <iostream>
#include <string>
#include <map>
#include <fstream>
#include "drawMenu.h"
#include "stringEncryption.h"

class CLogin
{
public:
short index;
map <short,string> username;
map <string,string> password;
string logInStatus;
void addUser();
void delUser(short id);
void display(short id);
void displayAll();
void changeUser(short id);
void logOut();
void handel(short id,bool& quit);
void saveFile();
void loadFile();
void eraseAll();
}storage;
void CLogin::addUser()
{
string tempUser,tempPass;
bool doContinue=0;

for(;Winky Winky
{
system("CLS");
cout<<"\n\tEnter a username: ";
getline(cin,tempUser);

if(tempUser=="")
{
system("CLS");
cout<<"\n\tNo username entered!";
Sleep(2000);
continue;
}

doContinue=0;

for(int i=index;i>0;i--)
if(username[i]==tempUser)
{
system("CLS");
cout<<"\n\tUser already exists!";
Sleep(2000);
doContinue=1;
}
if(doContinue)
continue;

for(;Winky Winky
{
system("CLS");
cout<<"\n\tEnter a password: ";
getline(cin,tempPass);

if(tempPass=="")
{
system("CLS");
cout<<"\n\tNo password entered!";
Sleep(2000);
continue;
}

break;
}
break;
}
index++;
username[index] = tempUser;
password[tempUser] = tempPass;
}
void CLogin::delUser(short id)
{
if(username[id]==logInStatus)
logInStatus = "Not Logged In";
for(int i=id;i<=index;i++)
{
username[i]=username[i+1];
password[username[i]]=password[username[i+1]];

password.erase (username[i+1]);
username.erase (i+1);
}
index--;
}
void CLogin::display(short id)
{
system("CLS");
cout<<"\n\tAccount id: "<<id;;
cout<<"\n\tAccount name: "<<username[id];
cout<<"\n\tAccount pass: "<<password[username[id]];
cout<<"\n\n\t";
system("PAUSE");
}
void CLogin::handel(short id,bool& quit)
{
if(id>index)
{
quit = 1;
return;
}

string message="Edit user: ";
message+=username[id];
bool boolReturn = 0;

for(;Winky Winky
{
system("CLS");
cout<<endl;

switch(drawMenu(message,"Display details|Delete|Return",1))
{
case 1: display(id); break;
case 2: delUser(id); boolReturn=1; break;
//case 3: changeUser(id); break;
case 3: boolReturn=1; break;
}
if(boolReturn)
return;
}
}
void CLogin::displayAll()
{
string users;
bool secondLayerQuit = 0;

for(;Winky Winky
{
system("CLS");
users = "";
if(index>0)
{
users+=username[1];
for(int i=2;i<index;i++)
{
users+="|";
users+=username[i];
}
if(index>=2)
{
users+="|";
users+=username[index];
}
users+="|";
users+="Return";
}
else
{
cout<<"\n\tNo users in the database!";
cout<<"\n\t";
system("PAUSE");
return;
}
cout<<endl;
handel(drawMenu("Users in the database",users,1),secondLayerQuit);
if(secondLayerQuit)
return;
}
}
void CLogin::changeUser(short id){
logInStatus=username[id];}
void CLogin::logOut(){
logInStatus="Not logged in";}

void CLogin::saveFile()
{
system("CLS");
string temp;

ofstream filestream;
filestream.open ("encryptedData.dat");

if(filestream)
{
for(int i=1;i<=index;i++)
{
temp = username[i];
enString(temp);
filestream << temp << endl;

temp = password[username[i]];
enString(temp);
filestream << temp << endl;
}
cout<<"\n\tFile saved!";
cout<<"\n\t";
system("PAUSE");
}
else
{
cout<<"\n\tError! Can not write to file!";
cout<<"\n\t";
system("PAUSE");
}
filestream.close();
}

void CLogin::loadFile()
{
string tempString;
cout<<endl;
bool alternate = true;

ifstream filestream ("encryptedData.dat");
if (filestream.is_open())
{
switch(drawMenu("Do you want to overwrite the current database with the savefile?","Yes|No",1))
{
case 1: system("CLS");break;
case 2: system("CLS");return;
}
eraseAll();
while ( filestream.good() )
{
if(alternate)
{
index++;
getline (filestream,tempString);
deString(tempString);
username[index]=tempString;
alternate = false;
continue;
}
else
{
getline(filestream,tempString);
deString(tempString);
password[username[index]]=tempString;
alternate = true;
continue;
}
}
//delUser(1);
cout<<"\n\tFile loaded!";
cout<<"\n\t";
system("PAUSE");
filestream.close();
}
else
{
cout<<"\n\tError! Unable to open file!";
cout<<"\n\t";
system("PAUSE");
}
}

void CLogin::eraseAll()
{
while(index>0)
{
password.erase (username[index]);
username.erase (index);
index--;
}
}

void checkAccess()
{
ifstream filestream ("cache.dat");
if (filestream.is_open())
{
bool alternate = true;
string lockUser,lockPass;
string attemptUser,attemptPass;
while ( filestream.good() )
{
if(alternate)
{
getline (filestream,lockUser);
deString(lockUser);
alternate = false;
continue;
}
else
{
getline(filestream,lockPass);
deString(lockPass);
alternate = true;
continue;
}
}

for(;Winky Winky
{
system("CLS");
cout<<"\n\tThis application requires you to log in!"<<endl;
cout<<"\n\tEnter username: ";
getline(cin,attemptUser);
cout<<"\tEnter password: ";
getline(cin,attemptPass);

if(attemptUser == lockUser && attemptPass == lockPass)
break;
system("CLS");
cout<<"\n\tWrong login!";
cout<<"\n\t";
system("PAUSE");
}
}
else
{
filestream.close();

string setUser,setPass;

ofstream filestream;
filestream.open ("cache.dat");

if(filestream)
{
for(;Winky Winky
{
cout<<"\n\tEnter a username to stop people accessing this application: ";
getline(cin,setUser);
if(setUser!="")
break;
system("CLS");
}
for(;Winky Winky
{
cout<<"\tEnter a password: ";
getline(cin,setPass);
if(setUser!="")
break;
system("CLS");
}
enString(setUser);
enString(setPass);

filestream << setUser << endl;
filestream << setPass<< endl;
filestream.close();
}

else
{
cout<<"\n\tError! Unable to store cache, Exiting program!";
cout<<"\n\t";
system("PAUSE");
}
}
}

int main()
{
checkAccess();
system("CLS");
storage.logInStatus = "Not logged in";
string message;
for(;Winky Winky
{
system("CLS");
message = "";
//message+="Log in system made by TheUberFail, Log in status: ";
//message+=storage.logInStatus;
message+="Password saver by TheUberFail ::Now with encryption!";
cout<<"\n";
switch(drawMenu( message,
"Display Users|Create user|Save|Load|Exit",
1)
)
{
case 1: storage.displayAll(); break;
case 2: storage.addUser(); break;
//case 3: storage.logOut(); break;
case 3: storage.saveFile(); break;
case 4: storage.loadFile(); break;
case 5: return 0;
}
}
}


:/

you know what vectors are right? are they useful for game programming?

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo