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.
Header File (we can not make 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 that I have created, as you can probably tell I dont know what I am doing. I am confused as to how to use the pointer properly from the header file and also I dont feel like I am initiating my object properly.
The first thing I see is that you have include guards in your source file, they are not required in source files, only headers should have include guards.
Second, you have pointers so you need to allocate or assign memory to these pointers.
You need an overloaded << operator in your class for this to work.
It might be easier at this stage to get the arrays right first, and then write an appropriate get method, and after that address operator overloading later.
PS the (2) get methods would return the std_alphabet and the c_alphabet like test.getAlphabet() and test.getCAlphabet(). Once you get them you can print them out with a loop.