Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I am taking an introduction level course of C++. Since, I am a beginner o

ID: 3916223 • Letter: H

Question

Hello, I am taking an introduction level course of C++. 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 ‘’.)
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.

I've already comfirmed that the program for Part 1 worked without any problem. However, I had a lot of errors, including syntax errors and throwing of erros anf felt difficulties in Part 2 . My understanding to concepts of C++ is not enough, so I can't even know which parts in my program I have to fix, and how I can do that. Please check my programs and help me.

My program is :

#include<iostream>

#include<cstring>

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 " <<letters1 << endl;

// 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] != '' && String2[i] != '')

{

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

return String1[i] - String2[i];

i++;

}

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

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] != '')

{

  

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] != '')

{

index++;

}

int index2 = 0;

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

name1[index] = name2[index2];

index++;

index2++;

}

name1[index] = '';

}

Explanation / Answer

1: comparison of 2 strings

There is a pre defined function which can be used for it.
int strcmp(const char *leftString, const char *rightString )

2: To calculate number of uppercase and lowercase
while (str[i] != 0){

if(str[i] >= 'a' && str[i] <= 'z'){
lowercase++;
i++;
}

else if (str[i] >= 'A' && str[i] <= 'Z'){
uppercase++;
i++;
}
}

3: to concate 2 strings

char str1[50], str2[50], res[100];

cout << "Enter string s1: ";
cin.getline(str1, 50);

cout << "Enter string s2: ";
cin.getline(str2, 50);

strcat(s1, s2);

cout << "s1 = " << s1 << endl;
cout << "s2 = " << s2;

return 0;

Try using these and let me know if there is still problem

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote