This assignment has me flustered with nowhere to go -- confusing to the extreme. I'm a novice to data structures, and this week's homework assignment has me lost and I don't know where to turn to for help. Learning a language was easy, but programming data structures is rather hard I must say! My problem? I don't know how to flesh out the functions that I've created. Here is the assignment for reference:
A signature of a string is an integer that is derived from that string. For this assignment, you will build a signature for strings by starting with a total sum of zero and, for each character (call it c) in the string, update the total using: total = total*2 + static cast<int>(c);
Note: The characters of a string s, may be accessed as follows:
for (string::size_type index = 0; index <s.length(); ++index)
//process char s[index]
Create a container class that stores a collection of strings. The class should have three public members: a constructor that initializes an empty collection, an insert function that adds one string to the collection, and a function that receives a data/string value and returns one of the data values (string/word) in the collection -- specifically, the value whose signature is numerically closest to the parameter's signature. Note: the class should not store signatures of all of the data (it should calculate as needed, using a private method). Also provide a main function and any other code/tools to complete a program that tests your class.
What should a fleshed-out set of functions look like? How should I start? I'm stuck!
Am I on the right track? How can I flesh out my functions to accurately reflect said assignment? Thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include <iostream>
#include <string>
#include <iomanip>
#include <chrono>
#include <ctime>
using namespace std;
//c = 0;
//total = total * 2 + static cast<int>(c);
//for (string::size_type index=0; index <s.length() ; ++index) //process char s[index]
class Container
{
public:
void empty();
string insert();
string returns();
protected:
int calc();
};
void Container::empty()
{
}
string Container::insert()
{
}
string Container::returns()
{
}
int Container::calc()
{
}
int main()
{
cout << "Do you want to read data from a file?";
system("PAUSE")
}
|