I have posted this a couple times and I have just been getting spam as a respons
ID: 3763639 • Letter: I
Question
I have posted this a couple times and I have just been getting spam as a response. please help, I am totally lost on this assignment and don't know where else to turn. Thank you in advance. The psudocode for this assignment is:
Open the specified file in binary mode, Save the file name in the fileNames array., Determine the file size using seekg and tellg, Read the file contents into the character array in one statement, Close the file ,Loop through the array, one character at a time and accumulate the sum of each byte, Store the sum into the checkSums array.
I have to use the funtions listed:
const int SUM_ARR_SZ = 100;
unsigned int checkSums[SUM_ARR_SZ];
string fileNames[SUM_ARR_SZ];
inFile.open(filePath.c_str(), ios::binary);
inFile.seekg(0, ios_base::end);
int fileLen = inFile.tellg();
inFile.seekg(0, ios_base::beg);
inFile.read(charArr, fileLen);
inFile.close();
inFile.clear(std::ios_base::goodbit);
this is what i have so far. It's probably garbage but hey its a start:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
// Declare Variables
char reply;
char menu();
string filePath;
void Calculate();
void Verify();
int main()
{
char choice;
choice = menu();
while (choice != 'Q')
{
switch (choice)
{
case 'A': Calculate();
break;
case 'B': Verify();
break;
default: cout << "invalid input ";
}
choice = menu();
}
return 0;
}
}
char menu()
{
char choice;
cout << "Please select: ";
cout << "A) Add checksum to specified file ";
cout << "B) Verify integrity of specified file ";
cout << "Q) Quit ";
cin >> choice;
return toupper(choice);
}
void Calculate()
{
const int SUM_ARR_SZ = 100;
unsigned int checkSums[SUM_ARR_SZ];
string fileNames[SUM_ARR_SZ];
char charArr[100000];
ifstream inFile;
inFile.open(filePath.c_str(), ios::binary);
inFile.seekg(0, ios_base::end);
int fileLen = inFile.tellg();
inFile.seekg(0, ios_base::beg);
inFile.read(charArr, fileLen);
cout << "File checksum = " << checkSums << endl;
inFile.close();
inFile.clear(std::ios_base::goodbit);
}
void Verify()
{
unsigned int checksum;
char ch, filename[30];
checksum = calculate(ch, filename);
checksum -= ' '; //don't count the last enter after the checksum
checksum = ~checksum;
++checksum;
checksum = checksum & 0x000000FF;
cout << "File checksum = " << checksum << endl;
if (checksum == 0)
cout << "The file integrity check has passed successfully. ";
else
cout << "The file integrity check has failed - the file has been compromised! ";
}