|
|||||||
| Programming, Coding, (Web)Design Discuss all your programming or design needs with likeminded people. |
![]() |
|
|
Thread Tools |
|
|
#1 |
|
DriverHeaven Newbie
Join Date: Jul 2002
Location: Portland, OR
Posts: 13
Rep Power: 0 ![]() |
Our assignment is to write an ecryption program that will accept user inputted text, and then switch around every other letter, then take the last character in each word and put it first, lowercase everything, then spit out the text. We aren't allowed to use Arrays at all though
![]() I'm having a hell of a time figuring out how to get the damn thing to nab the last character of a word and place it at the first character position. Here's what I have so far: ============================================ /************************* *****________________***** ****| Jesse Thompson |**** ****| CS 161 Prog #4 |**** ****| 07/17/02 |**** ****|________________|**** *************************/ #include <iostream> #include <streambuf> #include <istream> #include <string.h> #include <stdio.h> #include <string> string text; text = ""; using namespace std; main() { void UserInput(); if(choice = 1) void Encrypt(); if(choice = 2) void Decrypt(); void StringLength(); void SetPositionAndGet(); return 0; } // Prompts user as to rather or not they would like to encrypt // or decrypt their text int UserInput(void) { int choice; // The users choice input cout << "What would you like to do?\n" "\t 1. Encrypt \n" "\t 2. Decrypt \n" "\t Please enter your choice"; cin >> choice; } // Prompts the user for the text they would like to encrypt string Encrypt(void) { cout << "Please enter the text that you would like to encrypt\n"; cin >> text; } // Prompts the user for the text they would like to decrypt string Decrypt(void) { string text; // User defined text cout << "Please enter the text that you would like to decrypt\n"; cin >> text; } // Counts the amount of characters in text char StringLength(void) { char length[256]; text = length; strlen(length); } // Set position of get pointer at the end of the text entered // And then get that character int SetPositionAndGet(void) { seekg(length, text); char sgetc(); } ==================================== Any ideas? Am I on the right track? jesse ;-)
__________________
MSI KT3 Ultra-ARU AMD Athlon XP 1600+ Vantec CCK-6027D HSF Crucial PC2100 256mb DDR Maxtor 40GB 7200rpm ATA133 Leadtek geForce 2mx SH MAX 400 Philips CDRW1200 Philips 107S 17" Antec 1030 Enermax 350W
|
|
|
|
|
|
#2 |
|
A Legend in Underwear
Join Date: May 2002
Location: Unknown
Posts: 5,255
Rep Power: 70 ![]() |
I dont see how you can do it without using arrays because a string is an array of characters? Could you clarify this?
__________________
Gentoo Linux - Developer (baselayout) Read my blog "I contend that we are both atheists. I just believe in one fewer god than you do. When you understand why you dismiss all the other possible gods, you will understand why I dismiss yours." Stephen Roberts |
|
|
|
|
|
|
|
|
DriverHeaven Newbie
Join Date: Jul 2002
Location: Portland, OR
Posts: 13
Rep Power: 0 ![]() |
Quote:
I guess the only thing really holding me back right now is how to make the code pick a character, and move it. I'm not sure what command would have it pick a character, and what command would move it. I don't know wtf she's thinking. I'm going to go talk to her today. I have reworked my code though, just cleaned it up a bit, here's the update: Oh, and here's exactly what she wants us to do: 1. Read the text from either a user inputed sentence, paragraph, single word, or from a txt file. 2. Word by word, look for duplicate letters, if found, delete the second letter, and capatalize the first, then take the last character of the word and make it the first, and finally swap every other letter. 3. Also make it so that it can be decrypted to an output file. Okay here's my cleaned up code: ========================== /************************* *****________________***** ****| Jesse Thompson |**** ****| CS 161 Prog #4 |**** ****| 07/17/02 |**** ****|________________|**** *************************/ #include <iostream.h> #include <string> #include <fstream.h> #include <fstream> using namespace std; int main() { void FirstPrompt(void); FirstPrompt(); return 0; } // Prompt the user for what they would like to do void FirstPrompt(void) { int first_choice; void SecondPromptEncrypt(void); void SecondPromptDecrypt(void); cout << "Please choose from the following optoins:\n" "\t 1. Encrypt \n" "\t 2. Decrypt \n"; cin >> first_choice; if(first_choice = 1) SecondPromptEncrypt(); if(first_choice = 2) SecondPromptDecrypt(); } // Prompt user as to whether they would like to ecrypt a string of text // manually or from a file void SecondPromptEncrypt(void) { int second_choice; void EncryptionPromptManual(void); void EncryptionFilePath(void); cout << "You have two options, you can either encrypt\n"; cout << "a line of text that you input yourself, or \n"; cout << "you can encrypt an entire file. Please choose:\n" "\t 1. Input manually \n" "\t 2. Input from a file\n"; cin >> second_choice; if(second_choice = 1) EncryptionPromptManual(); if(second_choice = 2) EncryptionFilePath(); } // Prompt user as to whether they would like to ecrypt a string of text // manually or from a file void SecondPromptDecrypt(void) { int second_choice; void DecryptionPromptManual(void); void DecryptionFilePath(void); cout << "You have two options, you can either decrypt\n"; cout << "a line of text that you input yourself, or \n"; cout << "you can decrypt an entire file. Please choose:\n" "\t 1. Input manually \n" "\t 2. Input from a file\n"; cin >> second_choice; if(second_choice = 1) DecryptionPromptManual(); if(second_choice = 2) DecryptionFilePath(); } // Prompt user for the text they would like to encrypt via manaul input void EcryptionPromptManual(void) { int text_to_encrypt; cout << "Please enter the text that you would like to encrypt\n"; cin >> text_to_encrypt; } // Prompt user for the text they would like to decrypt via manaul input void DecryptionPromptManual(void) { int text_to_decrypt; cout << "Please enter the text that you would like to decrypt\n"; cin >> text_to_decrypt; } // Prompt the user for the path of the file they would like to encrypt void EncryptionFilePath(void) { char ch; char filename[12]; ifstream in; cout << "Please enter the path and name of the file that you\n"; cout << "would like encrypted.\n"; cin >> filename; in.open(filename); if(!in) cerr << "Error opening" <<filename; if(in) { ch = in.get(); while(!in.eof()) { cout << ch; ch = in.get(); } in.close(); } } // Prompt the user for the path of the file they would like to decrypt void DecryptionFilePath(void) { char ch; char filename[12]; ifstream in; cout << "Please enter the path and name of the file that you\n"; cout << "would like decrypted.\n"; cin >> filename; in.open(filename); if(!in) cerr << "Error opening" <<filename; if(in) { ch = in.get(); while(!in.eof()) { cout << ch; ch = in.get(); } in.close(); } } =========================== jesse ;-)
__________________
MSI KT3 Ultra-ARU AMD Athlon XP 1600+ Vantec CCK-6027D HSF Crucial PC2100 256mb DDR Maxtor 40GB 7200rpm ATA133 Leadtek geForce 2mx SH MAX 400 Philips CDRW1200 Philips 107S 17" Antec 1030 Enermax 350W
|
|
|
|
|
|
|
|
|
DriverHeaven Newbie
Join Date: Jul 2002
Location: Portland, OR
Posts: 13
Rep Power: 0 ![]() |
Okay n/m. I just called my professor and this whole thing is hella easier than I thought.
1. I don't have to be able to encrypt an entire file. 2. I don't have to decrypt anything. 3. The user has to enter the amount of characters they will be entering. So that in itself makes this whole thing hella easier, I should be able to bang this out in an hour. Thanx though. jesse ;-)
__________________
MSI KT3 Ultra-ARU AMD Athlon XP 1600+ Vantec CCK-6027D HSF Crucial PC2100 256mb DDR Maxtor 40GB 7200rpm ATA133 Leadtek geForce 2mx SH MAX 400 Philips CDRW1200 Philips 107S 17" Antec 1030 Enermax 350W
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
|
|