Question: Hello, I am looking a way to fix my program. Since, I am a beginner of programing, I amo totally stuck on this assesment. Could

Hello, I am looking a way to fix my program. Since, I am a beginner of programing, I amo totally stuck on this assesment. Could you help me out ?

PART 1: 1. Define a function to compare two strings s1 and s2. This function returns 0 if s1 = s2 and returns an integer equal to the subtraction of the ASCII codes of the first two different characters if s1 ? s2. For example, if s1 = ABCD and s2 = ABE, the function returns -2 because: the ASCII code of C the ASCII code of E = -2. As another example, this function returns 65 if s1 = ABA and s2 = AB (the ASCII Code of A the ASCII Code of \0.) 2. Define a function to count to number of lowercase and uppercase letters in an input string. DO NOT DEFINE TWO SEPARATE FUNCTIONS. Use the functions in the cctype header file in this function. 3. Define a function to append a string to the end of another string. Note: Use the const keyword in the parameter list of the above-mentioned functions when appropriate. PART 2: Write a program that reads 10 strings from keyboard and stores them in an array. This program then uses the functions defined in Part 1 to display the following information on the screen: 1. The minimum and the maximum string in the list. 2. For each string in the list, this program displays the string itself followed by the total number of its lowercase, the total number of its uppercase, and the total number of its non-alphabetic characters. 3. This program then concatenates all the 10 strings into a new string and displays it on the screen.

My instructor required us to build a program, consisiting of 4 parts : main function, and three sub functions. At the same time, I am not allowed to use string function; I have to use C-strings.

According to my instrucuter, my sub functions which I defined in Part 1 are all correct and don't need to fix. She said that I can use them for Part2. I am not allowed to define new sub functions for part 2. I need to use three sub functions difined in Part 1.

I have erros in Part 2 ( questions about 2D arrays ) . When I run this program and it went to part2, I got an error messeage : Run-Time zcheck Failure #2- Stack around the variable 'letters1' was corrupted.

Please show me a solution to fix Part 2. I need a solution in main program ( and I don't want to change three sub-functions themselves, if I can )

My program is :

#include

#include

using namespace std;

int CompareStrings(const char String1[], const char String2[]);

void countLowerUpper(char imput[], int &sumLower, int &sumUpper);

void appendStrings( char*, const char *);

int main()

{

const int sizeString1 = 10; // define the size of string1

const int sizeString2 = 10; // define the size of string2

int result; // To hold the result of comparing

// for No1 of Part1 //

char String1[sizeString1];

char String2[sizeString2];

cout << "Enter characters :";

cin.getline(String1, sizeString1);

cout << "characters you entered are :" << String1 << endl;

cout << "Enter chracters again :";

cin.getline(String2, sizeString2);

cout << "characters you entered are ; " << String2 << endl;

result = CompareStrings(String1, String2); cout << String1 << endl;

if (result == 0)

cout << "two characters are same " << endl;

else

cout << "the substraction of two characters is " << result << endl;

// For No2 of Part1 //

int sum1, sum2;

char imput[10];

cout << "Enter characters:";

cin.getline(imput, sizeof(imput));

countLowerUpper(imput, sum1, sum2);

cout << "the number of lower letters is " << sum1 << endl;

cout << "the number ofu upper letters is " << sum2 << endl;

// For No3 of Part1 //

char letters1[10];

char letters2[10];

cout << " enter letters :" << endl;

cin.getline(letters1, sizeof(letters1));

cout << "then, enter other letters :" << endl;

cin.getline(letters2, sizeof(letters2));

appendStrings(letters1, letters2);

cout << "the combined line is " <

// after this line, for Part2 !!

const int numOfstrings = 10;

int lengthOfstrings = 20;

char strings[10][20];

// ask user to enter 10 strings and make a list of 10 strings.

cout << "Enter a string :";

for (int i = 0; i < 10; i++) {

cout << "Enter letters of NO:" << i + 1 << endl;

cin.getline(strings[i], 20);

}

int i = 1;

// this is for question 1

char * max = strings[0];

char * min = strings[0];

while (i <= 10)

{

if (CompareStrings(strings[i], max) > 0)

max = strings[i];

if (CompareStrings(strings[i], min) < 0)

min = strings[i];

if (CompareStrings(strings[i], min) == 0)

max = min = strings[i];

i++;

}

cout << "the maximum letter is " << max << endl;

cout << "the minimum letter is " << min << endl;

// the end of question 1

// this part is for question2 (original place )

int totalLower, totalUpper;

int stringLength;

stringLength = strlen(strings[i]);

while (i <= 10)

{

countLowerUpper(strings[i], totalLower, totalUpper);

cout << "the total number of lowercase of No." << i << "is : " << totalLower << endl;

cout << "the total number of uppercase of No." << i << "is : " << totalUpper << endl;

cout << "the total number of non-alphabet of No." << i << "is : " << stringLength - (totalLower + totalUpper) << endl;

i++;

}

// this part is for the question 3 (original place )

for (int j = 0; j < 10; j++)

appendStrings(strings[i], strings[i + 1]);

cout << "the combined string is " << strings[i] << endl;

system("pause");

return 0;

}

int CompareStrings(const char String1[], const char String2[])

{

int i = 0;

while (String1[i] != '\0' && String2[i] != '\0')

{

if (String1[i] != String2[i])

return String1[i] - String2[i];

i++;

}

if (String1[i] == '\0' && String2[i] == '\0')

return 0;

else

return String1[i] - String2[i];

}

void countLowerUpper(char imput[], int &sumLower , int &sumUpper)

{

int i = 0;

int counterLower = 0;

int counterUpper = 0;

while (imput[i] != '\0')

{

if (islower(imput[i]))

{

counterLower++;

sumLower = counterLower;

}

else if (isupper(imput[i]))

{

counterUpper ++;

sumUpper = counterUpper;

}

i++;

}

}

void appendStrings( char *name1, const char *name2 )

{

int index = 0;

while (name1[index] != '\0')

{

index++;

}

int index2 = 0;

while (name2[index2] != '\0') {

name1[index] = name2[index2];

index++;

index2++;

}

name1[index] = '\0';

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!