Question: Download the attached file/s, copy and paste the code segment/s into your visual studio or any other C++ IDE and run it. You will have

Download the attached file/s, copy and paste the code segment/s into your visual studio or any other C++ IDE and run it. You will have to implement a small intentional bug in your program and post it for other students to debug.

To be able to receive your full discussion points, you need to submit the following.

Following is your check list and rubric

Attach your .cpp file/s with an implemented bug - 20pnts

Describe what the code does in detail - 20pnts

Debug at least one other program and submit your .cpp file - 40pnts (note what the bug was in comments)

After running the debugged program, attach the screen shot of your output- 20pnts

Here is the code I was given:

// This program demonstrates a function, countChars, that counts

// the number of times a specific character appears in a string.

#include

using namespace std;

int countChars(char *, char); // Function prototype

int main()

{

const int SIZE = 51; // Array size

char userString[SIZE]; // To hold a string

char letter; // The character to count

// Get a string from the user.

cout << "Enter a string (up to 50 characters): ";

cin.getline(userString, SIZE);

// Get a character to count occurrences of within the string.

cout << "Enter a character and I will tell you how many ";

cout << "times it appears in the string: ";

cin >> letter;

// Display the number of times the character appears.

cout << letter << " appears ";

cout << countChars(userString, letter) << " times. ";

return 0;

}

//****************************************************************

// Definition of countChars. The parameter strPtr is a pointer *

// that points to a string. The parameter Ch is a character that *

// the function searches for in the string. The function returns *

// the number of times the character appears in the string. *

//****************************************************************

int countChars(char *strPtr, char ch)

{

int times = 0; // Number of times ch appears in the string

// Step through the string counting occurrences of ch.

while (*strPtr != '\0')

{

if (*strPtr == ch) // If the current character equals ch...

times++; // ... increment the counter

strPtr++; // Go to the next char in the string.

}

return times;

}

Thank you in advance.

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!