Write a c program that prompts the user to enter a character

Assignment Help C/C++ Programming
Reference no: EM131945858

Assignment: Introduction to Programming in C

Instructions

This assignment consists of two problems.

1. Run-Length Decoding

Run-length encoding is a relatively simple technique for compressing data; if a particular value (or substring) appears multiple times in a row, it is only represented once, followed by an integer indicating the number of times it should be repeated. For example, the string "AAAAA" can be compressed to "A5" (5 occurrences of 'A'), saving three characters.

Write a C program that prompts the user to enter a character to count and and string (character sequence) to process. Store the string in a char array; you may assume that the user will never enter more than 500 characters, so make the array 501 elements long (to account for the null-terminator). You may further assume that the string is run-length encoded with an even number of characters (each pair of characters consists of a printing character followed by a digit representing its repetition count). Your program should define and print the results of calling two functions (be sure to use pointers carefully in your loops!):

a. int countTotal (char *)

This function processes the input string and returns the total number of characters in the decoded result. For example, given the input "a3b7a2c4", the function would return 16. Hint: You don't need to reconstruct the original string to solve this problem!

b. int countChar (char *, char)

This function takes the input string, followed by the search character, as arguments. It returns the total number of times the search character will occur in the decoded result. For example, given the input string "a3b7a2c4", the function would return 5 ('a' occurs in two places in the decoded result, first in a triplet and then in a pair). Hint: As with countTotal(), you don't need to reconstruct the original string to solve this problem!

2. Processing Product Ratings

Myrmidon, Inc,. sells various products online, and has hired you to analyze product feedback left by satisfied (or not-so-satisfied) customers in the form of star ratings. A customer can rate a product on a scale of one to ten stars - the more stars, the better- regarded the product is. Each product is identified by a unique (integer) product number, ranging from 1 through the total number of products offered. Your job is to write a program that reads in an arbitrary number of pairs of integers (a product number, followed by a single space, followed by an integer rating from 1 through 10) and then prints a neatly formatted report listing the rating breakdown for each product, plus the average rating (as a float with 2 decimal places) for that product and the total number of ratings processed. If a product has no ratings, it should be omitted from the final report.

When you first run your program, it should ask for the total number of unique products that are sold. It should then use a loop (most likely a while loop) to read in as many product ratings as the user cares to enter. When the user input stops, the program should calculate and print out the final report. Hint: Use scanf() rather than getchar() to read in two values at a time and test the value that scanf() returns each time it is called. When scanf() returns a value other than 2, stop the loop and generate your report.

Use a two-dimensional int array to store the ratings (one row per product, one column per possible rating value). Remember that array indexes begin at 0, but product identifiers (and ratings) start at 1. You will need to either use an offset value in your array indexes or (this is the easier option) simply create your array with one more row and column than you need, and skip row 0 and column 0. To simplify your life later, you may also want to create extra array columns to store the quantities and sums of each product's ratings.

For example, consider the following sample program execution (program output is in italics, and user input is in bold):

How many unique products are there? 4

Enter product number and rating (1-10), separated by a space, one pair at a time:
1 1
1 1
2 1
2 8
4 1
4 8
1 5
1 3
3 8
3 3
2 7
4 10
3 5
3 3
3 9
1 1
3 10
1 9
4 6
2 3
3 3
1 5
2 6
4 9
2 4

Product 1 Information:
1 star: 3
2 star: 0
3 star: 1
4 star: 0
5 star: 2
6 star: 0
7 star: 0
8 star: 0
9 star: 1
10 star: 0

Average rating: 3.57 out of 10 (7 ratings total).
--------------------
Product 2 Information:
1 star: 1
2 star: 0
3 star: 1
4 star: 1
5 star: 0
6 star: 1
7 star: 1
8 star: 1
9 star: 0
10 star: 0
Average rating: 4.83 out of 10 (6 ratings total).
--------------------
Product 3 Information:
1 star: 0
2 star: 0
3 star: 3
4 star: 0
5 star: 1
6 star: 0
7 star: 0
8 star: 1
9 star: 1
10 star: 1

Average rating: 5.86 out of 10 (7 ratings total).
--------------------
Product 4 Information:
1 star: 1
2 star: 0
3 star: 0
4 star: 0
5 star: 0
6 star: 1
7 star: 0
8 star: 1
9 star: 1
10 star: 1
Average rating: 6.80 out of 10 (5 ratings total).
--------------------
25 product ratings evaluated in all.

In order to save you from spending too much time typing and retyping input data to test your code, we have provided you with several small-to-medium data files that contain test input. If you run your program from the command line (e.g., the Terminal in OS X or the command prompt on Sparky), you can use the left arrow (<) operator to redirect the contents of these files into standard input for your program, e.g.:

a.out < testdata1.txt

You may also be able to copy and paste the contents of the sample data files into the console in CLion, Netbeans, or Xcode.

Reference no: EM131945858

Questions Cloud

How many grams of h2o will you make : You start with 150.0 g of pentane and 500.0 L of O2. How many grams of H2O will you make?
Find the simple moving average : For this assessment, suppose that you are the operations manager for ABC Manufacturing, a small manufacturing company founded three years ago.
Finding the current price of the bond : Black Water Corp. just issued zero-coupon bonds with a par value of $1,000. The bond has a maturity of 21 years and a yield to maturity of 7.56 percent.
What is the yield to maturity for the bonds : Blue Crab, Inc plans to issue new bonds, but is uncertain how the market would set the yield to maturity. The bonds would be 15-year to maturity.
Write a c program that prompts the user to enter a character : Write a C program that prompts the user to enter a character to count and and string (character sequence) to process. Store the string in a char array.
Maximum concentration possible : Calculate the solubility, i.e., the maximum concentration possible, of silver sulfate in water Give the answer in mol/L of Ag2SO4.
What is the net income for the firm : Billy's Exterminators, Inc., has sales of $607,000, costs of $314,000, depreciation expense of $66,000, interest expense of $43,000.
Sodium hydroxide solution required : What volume of 1.5 M sodium hydroxide solution is required to completely neutralize 250 mL of 4.0 M sulfuric acid?
Create a work breakdown structure : You create a work breakdown structure, identify all the task dependencies, and calibrate your minimum, most likely and maximum durations for each task.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd