I am a complete beginner with c++ and up to this point in school we have only learned and used Java. Our first project this year is to create a caesar cipher but we must use the header file provided by our professor. At this point I am only trying to shift the letters and prove my concept before coding the encrypting and decrypting methods. Any help as to what I am doing wrong and why this code isnt compiling would be amazing.
This is our Header file, we are not allowed to make any changes to this file at all:
// include file for Caesar cipher code
//
#ifndef CAESAR_H
#define CAESAR_H
#include <string>
class Caesar {
private:
//pointers used to refer to the standard alphabet array and the Caesar shift array
char* std_alphabet;
char* c_alphabet;
public:
// The constructor . . .
// create the two arrays with the c_alphabet array contents representing the std_alphabet
// characters shifted by a value of the shift parameter
Caesar(int shift = 0);
// encrypt a message. Returns count of characters processed
// first string is message, second is encrypted string
int encrypt(const std::string& message, std::string& emessage);
// decrypt a message. Returns count of characters processed
// first string is encrypted string, second is decrypted string
int decrypt(const std::string& message, std::string& dmessage);
//delete any memory resources used by the class
~Caesar();
}; // end of class . . .
#endif
This is my .cpp file, I am only in the stage of currently trying to shift my alphabet in an array but I do not understand why my header file is using pointers or if I am creating my arrays properly(I was able to get this concept to work in a separate file but not using the header file). I am only trying to print the lines to make sure this works before going forward with any coding:
#ifndef CAESAR_C
#define CAESAR_C
#include <string>
#include <iostream>
#include "Caesar.h"
using namespace std;
int shift, i, k;
char letter = 'a';
Caesar::Caesar(const int n) {
shift = n;
std_alphabet[26];
c_alphabet[26];
for (i = 0; i < 26; i++) {
std_alphabet[i] = letter;
letter++;
}
for (i = 0; i < 26; i++) {
cout << std_alphabet[i] << " ";
}
cout << endl;
for (i = 0; i < 26; i++) {
k = (i + shift) % 26;
c_alphabet[i] = std_alphabet[k];
}
for (i = 0; i < 26; i++) {
cout << c_alphabet[i] << " ";
}
};
#endif
This is my test file, I dont really know how to initiate a Caesar object properly. Like I said I am a complete beginner with c++ and would greatly appreciate any directions:
#include <string>
#include <iostream>
#include "Caesar.h"
using namespace std;
int main() {
Caesar* test = new Caesar(5);
cout << test;
system("PAUSE");
return 0;
};