Thread: textfile questions

  1. #1
    C++No0b!!!
    Join Date
    Jul 2005
    Location
    penn
    Posts
    66

    textfile questions

    i have a couple questions about textfiles...

    1. how do you make a folder to put the textfile into?

    i want to have a folder that uses the first and last name given from user input that would hold the textfile specific to that person

    2. how do you make it so u can log into that folder using a password and recall info from the textfile.

    the information that goes into the textfile is input which is the first name and last name, which they must use to log in, as well as a 7 digit password. so now there in there account and that tells them what there statement balance is from last time and they can put more in or take some out in the deposits and withdrawls.



    Code:
    //This program written by Dan Kemper
    //This program will balance your checkbook and print the results to a textfile named "checkbook.txt" or print the scrren to your printer
    //Suggestions and other comments can be sent to my email: [email protected]
    
    //Includes Header Files
    #include <iostream>	
    #include <fstream>	
    #include <iomanip>	
    
    using namespace std;	
    
    int main ()
    {
       //Declares variables
       char FirstName[20];
       char LastName[30];
       char Account[9];
       int PrintStatement;
       float Balance;
       float Deposits;
       float Withdrawls;
       float NewBalance;
    
    
       //Makes Textfile
       ofstream outfile ("checkbook.txt",ios::trunc);
       
       //Outputs to screen
       cout << "       AAA         TTTTTTTTTTTTTTT  MMMMM             MMMMM\n";
       cout << "      AAAAA        TTTTTTTTTTTTTTT  MMMMMM           MMMMMM\n";
       cout << "     AAA AAA            TTTTTT      MMM MMM         MMM MMM\n";
       cout << "    AAA   AAA           TTTTTT      MMM  MMM       MMM  MMM\n";
       cout << "   AAAAAAAAAAA          TTTTTT      MMM   MMM     MMM   MMM\n";
       cout << "  AAAAAAAAAAAAA         TTTTTT      MMM    MMM   MMM    MMM\n";
       cout << " AAA         AAA        TTTTTT      MMM     MMM MMM     MMM\n";
       cout << "AAA           AAA       TTTTTT      MMM      MMMMM      MMM\n";
       
       cout<<"\nPress [ENTER] to continue...\n";
       cin.get();
       
       cout << "\n\nThis program balances your checkbook.\n\n";
       cout << "First Name: ";
    
       //Asks user for input
       cin.get(FirstName, 20);
       cin.ignore(80, '\n');
       cout << "Last Name: ";
       cin.get(LastName, 30);
       cin.ignore(80, '\n');
       cout << "Account number: ";
       cin.get(Account, 9);
       cin.ignore(80, '\n');
       cout << "\n\nStatement balance: ";
       cin >> Balance;
       cin.ignore(1);	
       cout << "\nOutstanding deposits: ";
       cin >> Deposits;
       cin.ignore(1);	
       cout << "\nOutstanding withdrawls: ";
       cin >> Withdrawls;
       cin.ignore(1);	
    
       //Conversions
       NewBalance = Balance + Deposits - Withdrawls;
    
       //Output Results
       cout << "\nNew balance: ";
       cout << setiosflags (ios::fixed) << setprecision(2) << NewBalance;
       
       cout << "\n\nDo you want the above information to be printed to a textfile? (Y/N)\n";
       cin >> PrintStatement;
       cin.ignore(1);	
    do
    {
       //Prints to Textfile
       outfile << "Name: " << FirstName << " " << LastName << "\n";
       outfile << "Account Number: " << Account << "\n";
       outfile << "Statement Balance: " << Balance << "\n";
       outfile << "Outstanding Deposits: " << Deposits << "\n";
       outfile << "Outstanding Withdrawls: " << Withdrawls << "\n";
       outfile << "New Balance: " << setiosflags (ios::fixed) << setprecision(2) << NewBalance;            
    }
    while (PrintStatement=='y' || PrintStatement=='Y');
    
    cout << "Thank You!";
       
       outfile.close();
       
       //Stops program until button is pressed
       cin.get();
       return 0;
    }
    anyone understand what i'm tryin to do? just like a real ATM, sort of.

  2. #2
    C++No0b!!!
    Join Date
    Jul 2005
    Location
    penn
    Posts
    66
    i guess that was pretty hard to understand what i'm goin for huh?

    okay i want it to open the ATM thing to show up with the "press ENTER..." changed to "Type [r] if your a registered user, type [u] if your unregistered and wish to make an account, or press [q] to quit." ...waits for user input...

    if "r" then you type your full name (first and last name) and 7 digit account number which if correct will recall your previous balance (from a textfile made after registering located in a folder with the users full name as the title)and will ask for more input (deposits and withdrawls) which will alter the balance and save it back into the textfile for later use.

    if "u" then it asks for your first and last name as well as deposits which will decide your balance and your 7 digit password and saves it to a textfile (textfile names after date and time) when asked if all above information is true and makes a folder titled with the name of users full name which holds the textfile.

    can anyone help me? i think i'm just tryin to do too advanced stuff for my noobish abilities as of this point.

  3. #3
    He's trying.
    Join Date
    Apr 2005
    Location
    Missouri, US
    Posts
    70
    I'd recommend you start using C++ strings with <string>.

    If you were to use them, maybe something like this would be a start:
    Code:
    char status;
    cout << "Are you already registered?  Please enter \"r\" if yes, \"u\" if unregistered: ";
    cin >> status;
    
    string first, last;
    cout << "Please enter your first and last name: ";
    cin >> first >> last;
    
    if (status == 'u' || status == 'U')
    {
    	// makes a system call to create a directory with the first & last name
    	string syscall = "mkdir " + first + last;
    	system( syscall.c_str() );
    }
    
    // makes the filepath "\firstlast\checkbook.txt" - will already exist if registered, or was just
    // created if they were unregistered
    string filepath = "\\" + first + last + "\\checkbook.txt";
    ofstream outfile( filepath.c_str() );
    
    // Do all that deposit/withdrawl stuff
    Naturally not guaranteed to work since I just wrote it without testing and there may be an obvious flaw and I'm not that awesome at coding...Hope it helps though.

  4. #4
    Registered User Mortissus's Avatar
    Join Date
    Dec 2004
    Location
    Brazil, Porto Alegre
    Posts
    152
    Creating dir is OS specific. For Linux:

    #include <sys/stat.h>
    #include <sys/types.h>

    int mkdir(const char *pathname, mode_t mode);

    For Windows there are some nasty stuff here. But I never used them.

  5. #5
    He's trying.
    Join Date
    Apr 2005
    Location
    Missouri, US
    Posts
    70
    Quote Originally Posted by Mortissus
    Creating dir is OS specific. For Linux:

    #include <sys/stat.h>
    #include <sys/types.h>

    int mkdir(const char *pathname, mode_t mode);

    For Windows there are some nasty stuff here. But I never used them.
    Eep. Yeah, probably much safer/smarter to go without the system calls. Didn't know how though.

  6. #6
    C++No0b!!!
    Join Date
    Jul 2005
    Location
    penn
    Posts
    66
    so i cant make a directory? hmmm i think i may be in over my head. i'm not so shure i understand the strings and stuff yet.

  7. #7
    Banned
    Join Date
    Jun 2005
    Posts
    594
    how bout this

  8. #8
    C++No0b!!!
    Join Date
    Jul 2005
    Location
    penn
    Posts
    66
    i need an axample to look at, tutorials like that are imposible for me to learn from. i have gone through many many tutorials for other langs and i was left quit confused

  9. #9
    Banned
    Join Date
    Jun 2005
    Posts
    594
    humm ok well i was going thru soem stuff for windows,
    and apparently you can encrypt a folder with a user key,
    its a windows capability so maybe youd like to do that?
    if you are interested in it i will go thru the msdn find out the
    information attempt it myself and post the code ?

  10. #10
    C++No0b!!!
    Join Date
    Jul 2005
    Location
    penn
    Posts
    66
    okay i was given a way to make the directory from sandman that hopefully will work and if it doesnt i'll scrap the program or ask agen...

  11. #11
    Banned
    Join Date
    Jun 2005
    Posts
    594
    Code:
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    int main()
    {
    	//this create a directory
    	if(!CreateDirectory("c:\\NEW Directory\\", NULL))
    	{
    		cout << "Could not create new directory!" << endl;
    	}
    	else
    	{
    		cout << "Directory Created!" << endl;
    	}
    
    	//this encrypt the file, but i dont think it will
    	//do your situation much good, plus i dont know
    	//how to set keys for it, if you even can set a key
    	//for it, but might be fun to play around with.
    	if(EncryptFile("c:\\NEW Directory\\") > 0)
    	{
    		cout << "Encrypt Successful" << endl;
    	}
    	cin.get();
    	return 0;
    }

  12. #12
    C++No0b!!!
    Join Date
    Jul 2005
    Location
    penn
    Posts
    66
    hmm and the encryption is just to like password protect it or wut?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM