ok so no lies this is for an assignment. I am sooo lost and freaking out about this program. So I had to switch my major from comp science cause I'm finding out its not for me but I still have to get this class done.
So here are his instructions.
Please write a program that:
1.
Accepts up to 50 characters from the keyboard
2.
Stores these characters in an array
3.
Encrypts the characters in the array
4.
Displays the now-encrypted characters on the screen
5.
Decrypts the characters in the array
6.
Displays the now-decrypted characters on the screen
Your program requires these 4 functions:
pre: none
post: returns true if the parameter is alphabetic, false otherwise
bool alphabetic(char ch)
pre: array has been declared, size has been initialized
post: user has been prompted for input. array has up to fifty characters accepted from keyboard. Size contains the number of characters stored in the array.
void fillArray(char array[], int& size)
pre: array has been declared, size has been initialized to the size of the array
post: array has been encrypted according to this algorithm:
if the character encountered is alphabetic
if the character encountered is in the first half of the alphabet
add 13 to the character
else
subtract 13 from the alphabet
else
do nothing.
void rot13(char array[], int size)
pre: none
post: returns true if the character is from the first half of the alphabet, false otherwise
bool firstHalf(char ch)[/i]
so here is what I have so far...
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
//pre: none
//post: returns true if the parameter is alphabetic, false otherwise
bool alphabetic(char ch);
//pre: array has been declared, size has been initialized
//post: user has been prompted for input. array has up to fifty characters accepted from keyboard. Size contains the number of characters stored in the array.
void fillArray(char array[], int& size);
//pre: array has been declared, size has been initialized to the size of the array
//post: array has been encrypted according to this algorithm:
void rot13(char array[], int size);
//pre: none
//post: returns true if the character is from the first half of the alphabet, false otherwise
bool firstHalf(char ch);
int main ()
{
char a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
bool goodinp;
fillArray (size);
goodinp = alphabetic (ch);
if (goodinp)
{
a = 0;
b = 1;
c = 2;
d = 3;
e = 4;
f = 5;
g = 6;
h = 7;
i = 8;
j = 9;
k = 10;
l = 11;
m = 12;
n = 13;
o = 14;
p = 15;
q = 16;
r = 17;
s = 18;
t = 19;
u = 20;
v = 21;
w = 22;
x = 23;
y = 24;
z = 25;
}
bool alphabetic(char ch)
{
char 'a'
bool character = true;
if (ch != a)
{
character = false;
return 0;
}
}
void fillArray(char array[50], int& size)
{
cout<<" Please enter up to 50 characters";
cin>> size;
}
Now please don't think I'm waiting for someone else to do this program for me I want to know how to do it but I'm stuck on what I need to do here and don't know where to go!!
right now I'm trying to get the program to return true if the letters are alphabetic in the bool alphabetic (char ch) and false if its anything else. The void fillArray (char array [50], int& size) accepts up to the 50 characters. I'm just trying to get this little bit done to make sure I have it correct.
Also please remember that I have to keep this in the confines of what the instructor asked so if you could point me in the right direction I would really appreciate it!!!!
Yeah, after reading your code, I can tell you really have no idea what you're doing.
1. isalpha() defined in cctype will tell you if what you pass is a letter or not. http://www.cplusplus.com/reference/clibrary/cctype/isalpha.html
2. ROT13 can be performed on ASCII with simple transformations:
a. Note that 'A' is at 65 and 'a' is at 97. This means that you can easily transform a letter to a number by subtracting 65 or 97 from it: 'A'-65=0, 'B'-65=1, and so on. You don't need to acutally type the values. Having a char variable named 'letter', you can do letter-='A';
b. It's possible to save yourself the verification of whether the letter is >=N. You just need to add 13 to the value and play around with the modulo operation.
c. Now you just need to restore the letter to its original value (if the letter was originally upper case, you'd add 'A', otherwise, 'a').
ok So I got this far and it compiles. I know that just because it compiles it doesn't mean that there aren't any problems so here it is... OH also I'm trying to get the message asking for an imput of characters to show up as asked through Void fillArray (char array[], int& size) but after I compile it and run the program it just remains blank. Please help!!!
//pre: none
//post: returns true if the parameter is alphabetic, false otherwise
bool alphabetic (char ch);
//pre: array has been declared, size has been initialized
//post: user has been prompted for input. array has up to fifty characters accepted from keyboard. Size contains the number of characters stored in the array.
void fillArray(char array[], int& size);
//pre: array has been declared, size has been initialized to the size of the array
//post: array has been encrypted according to this algorithm:
void rot13(char array[], int size);
//pre: none
//post: returns true if the character is from the first half of the alphabet, false otherwise
bool firstHalf(char ch);
const char MAX = 50;
int main ()
{
//If I put fillArray (array, size) here i have to declare array and size...however everytime I try to declare size it says its an invalid conversion from char to char and I have also tried int but no luck...
return 0;
}