Question

In: Computer Science

Assume the following declarations have been made: ----------------------------------- char item[50]; char guess; ----------------------------------- Furthermore, suppose that...

Assume the following declarations have been made:

-----------------------------------
char item[50];
char guess;

-----------------------------------
Furthermore, suppose that all of the elements of an item have already been initialized, and that the user has already entered a value for guess.


Write a code fragment to find and print out each index i for which item[i] is the same as guess.

Be sure to specify any additional necessary variable declarations.


As an example, consider the case where the rst 10 elements of item are (in order)
'a', 'b', 'c', 'd', 'a', 'b', 'b', 'c', 'f', 'a',


and the remaining elements are all 'y'. If guess were 'b', then your code should print out the following indices:
1 5 6

Solutions

Expert Solution

Here is the completed code snippet for this problem. Assuming the language is C or C++. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

//looping from i=0 to i=49

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

      //comparing item at index i with guess

      if(item[i]==guess){

            //printing the index followed by a space

            cout<<i<<" ";

            //if the language is C, use: printf("%d ",i);

      }

}

//printing newline character at the end.

cout<<"\n";

//if the language is C, use: printf("\n");


Related Solutions

Given the following variable declarations: const size_t n = 50; Write the declaration of an array...
Given the following variable declarations: const size_t n = 50; Write the declaration of an array of pointers to n memory blocks containing 16-bit signed integer values. Use 'x' for the name of the variable. (Don't forget the semi-colon at the end of the declaration!)
Suppose that strong claims, with weak evidence, have been made about the efficacy of an herbal...
Suppose that strong claims, with weak evidence, have been made about the efficacy of an herbal treatment for attention deficit disorder (ADD). You are a research assistant for a professor who decides to empirically test the validity of these claims. You locate 10 fifthgrade students, in 10 different classrooms, who have been diagnosed with ADD. Sitting unobtrusively at the back of each classroom with stopwatch in hand, you record the number of seconds that the child with ADD is out...
Suppose that we have a process that produces two types of an item: Blue Item and...
Suppose that we have a process that produces two types of an item: Blue Item and Orange Item. Both of the items require the same pure sequential operations: O1, O2, O3. O1 and O3 are manual operations. O2 is the main and an automated operation which differentiates the items (e.g. gives different colors). Operation 1 takes 1 minutes per item. It is a manual operation that is common to both types. Operation 2 takes 4 minutes per item. It is...
Suppose that we have a process that produces two types of an item: Blue Item and...
Suppose that we have a process that produces two types of an item: Blue Item and Orange Item. Both of the items require the same pure sequential operations: O1, O2, O3. O1 and O3 are manual operations. O2 is the main and an automated operation which differentiates the items (e.g. gives different colors). Operation 1 takes 1 minutes per item. It is a manual operation that is common to both types. Operation 2 takes 4 minutes per item. It is...
*******Using EXCEL**** Suppose that strong claims, with weak evidence, have been made about the efficacy of...
*******Using EXCEL**** Suppose that strong claims, with weak evidence, have been made about the efficacy of an herbal treatment for attention deficit disorder (ADD). You are a research assistant for a professor who decides to empirically test the validity of these claims. You locate 10 fifthgrade students, in 10 different classrooms, who have been diagnosed with ADD. Sitting unobtrusively at the back of each classroom with stopwatch in hand, you record the number of seconds that the child with ADD...
Item 3 Item 3 You have just been hired by FAB Corporation, the manufacturer of a...
Item 3 Item 3 You have just been hired by FAB Corporation, the manufacturer of a revolutionary new garage door opening device. The president has asked that you review the company’s costing system and “do what you can to help us get better control of our manufacturing overhead costs.” You find that the company has never used a flexible budget, and you suggest that preparing such a budget would be an excellent first step in overhead planning and control. After...
For this project, following assumptions have been made:   The booking is only open for the next...
For this project, following assumptions have been made:   The booking is only open for the next seven days from the current date. Only two categories of the plane can be booked i.e. Economy and Business. The total number of tickets that can be booked in each category is 10 only. By ‘user’, we mean the person who is booking the ticket for the passenger(s). For example, an employee of Saudi Airline. Your project should include information about the following entities...
Suppose you have been tasked with regulating a single monopoly firm that sells 50-pound bags of...
Suppose you have been tasked with regulating a single monopoly firm that sells 50-pound bags of concrete. The firm has fixed costs of $30 million per year and a variable cost of $1 per bag no matter how many bags are produced. a. If this firm kept on increasing its output level, would ATC per bag ever increase? Is this a decreasing-cost industry? b. If you wished to regulate this monopoly by charging the socially optimal price, what price would...
Suppose you have been tasked with regulating a single monopoly firm that sells 50 kilogram bags...
Suppose you have been tasked with regulating a single monopoly firm that sells 50 kilogram bags of concrete. The firm has fixed costs of $10 million per year and a variable cost of $2 per bag no matter how many bags are produced. a. If this firm kept on increasing its output level, would ATC per bag ever increase? (Click to select)YesNo.      Is this a decreasing-cost industry? (Click to select)YesNo. b. If you wished to regulate this monopoly by...
Suppose you have been tasked with regulating a single monopoly firm that sells 50-pound bags of...
Suppose you have been tasked with regulating a single monopoly firm that sells 50-pound bags of concrete. The firm has fixed costs of $30 million per year and a variable cost of $3 per bag no matter how many bags are produced. A. If this firm kept on increasing its output level, would ATC per bag ever increase? B. Is this a decreasing-cost industry? C. If you wished to regulate this monopoly by charging the socially optimal price, what price...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT