I dont clearly understand bool functions. this lends problems to my current assignment in class where i have to write a program that involves a bool function that tests for letters in a string that the user inputs. Can anyone offer help to me? the whole code is slightly confusing and i have worked on it for about 4 days now. reappraisal and help would be nice.
#include <iostream>
#include <string>
#include <algorithm>
// Function Prototypes=========================================================
// Do NOT change the signature of these function prototypes.
// If you do, your code will not compile with my altered main() function
// I suggest that you copy the prototypes below and then fill them in.
// ----------------------------------------------------------------------------
// Read in a line of text INCLUDING SPACES into a string.
// You may assume that the input will NOT exceed the maxLength available.
// Keep in mind that cin stops reading at a whitespace. See page 318.
void ReadString(char * c, int maxLength);
// Get the length of the string and store it in length
// Hint: How does C++ terminate a string? Look for that character!
void GetStringLength(char * c, int * length);
// PrintString - Just print the string in forward order using cout
void PrintString(char * const c);
// PrintStringBackwards - Print the string in reverse order using cout
void PrintStringBackwards(char * const c);
// Return a pointer to the character at the index given
char * GetValueAtIndex(char * const c, int index);
// Return true/false if the string contains the testVal
bool SearchString(char * c, char testVal);
// ============================================================================
//[BEGIN MAIN] -- Don't delete this line
int main()
{
// Use these variables to test.
// SIZE could change so make sure your code works with different sizes.
const int SIZE = 100;
char ca[SIZE];
char * pc = ca;
// Your code below
// =========================
// tests the ReadString function
int maxLength;
std::cout << "Enter string length: ";
std::cin >> maxLength;
std::cout << std::endl;
ReadString( ca, maxLength); // sends to the ReadString function
// tests GetStringLength function
int * length = 0;
std::string s1;
GetStringLength( pc, length); // sends to the GetStringLength function
//test PrintString(char * const c)
PrintString(pc);
//test void PrintStringBackwards(char * const c)
char x = 0;
PrintStringBackwards(pc); // sends to PrintStringBackwards function
// test char * GetValueAtIndex(char * const c, int index);
int index = 0;
GetValueAtIndex(pc, index);
// test bool SearchString(char * c, char testVal)
char testVal = 0;
SearchString(pc, testVal);
// =========================
// Your code above
std::cout << "Press ENTER";
std::cin.get();
return 0;
}
//[END MAIN] -- Don't delete this line
void ReadString(char * c, int maxLength)
{
std::cout << "Enter a string less than " << maxLength << " characters." << std::endl;
// Your code here
// ==============================
char s1;
std::cin >> s1; // enters a string
// ==============================
}
void GetStringLength(char * c, int * length)
{
//========================
std::string s1;
std::cout << s1.length() << std::endl;
//========================
}
void PrintString(char * const c)
{
//========================
std::string s1;
std::cout << s1; // prints out string
//========================
}
void PrintStringBackwards(char * const c)
{
//=======================
char s1[200000];
if (std::cin.getline(s1, sizeof s1)) // prints the string in reverse
{
for (size_t i = strlen(s1) - 1; i != -1; i--)
std::cout<< s1[i];
std::cout << s1[0] << std::endl;
}
//=======================
}
char * GetValueAtIndex(char * const c, int index)
{
//=======================
std::string s1;
std::cin >> index;
std::cout << "Character at index " << index << ": " << s1.substr(index) << std::endl;
//=======================
return 0;
}
bool SearchString(char * c, char testVal)
{
//====================
//====================
}
// You need to provide the rest of the functions
// See Function Prototypes at the top.