Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 18th International Conference Dasfaa 2013 Wuhan China April 22 25 2013 Proceedings Part 2 Lncs 7826

Authors: Weiyi Meng ,Ling Feng ,Stephane Bressan ,Werner Winiwarter ,Wei Song

2013th Edition

3642374492, 978-3642374494

More Books

Students also viewed these Databases questions

Question

Describe the nature of negative messages.

Answered: 1 week ago