[Solved] SOLVED: Assignment #6

$25

File Name: SOLVED:_Assignment_#6.zip
File Size: 197.82 KB

SKU: [Solved] SOLVED: Assignment #6 Category: Tag:
5/5 - (1 vote)

Program A: Averaging (averaging.c): Help! The key on my keyboard is broken. (Shhhdont point out the flaw in my story that I just typed it there.) I need to average a list of numbers that I will input, but I cant input negative numbers without being able to push the minus key. So instead, Ive created an alternate way to enter this list. Input a list of numbers in my special format, then output their average. My format consists of the following: each number will start with a n, p, or e. If it starts with an n or p, that character will be followed by a space and then a positive integer, the value of this number. If the character is an n, then the number should be negative if the character is a p, the number should be positive. If the character is an e, then this is the end of the list (nothingwill be after it). Your program should have and use the following function (written by you):// Precondition: value will be a pointer to where the input value is// to be stored.// Postcondition: returns true if a number was read, or false if// it was the end of the list. The int pointed to by value will be// set to the number input by this function, made negative or// positive depending on the character before it.int read_number(int* value)Sample Run (user input in bold and italics):p 1p 2p 10n 3e2.50Sample Run (user input in bold and italics):p 100p 40n 20n 123p 5e0.40Hint: dont forget, scanf takes pointers: dont pass it a pointer to a pointer.Program B: Twos and Threes (twosandthrees.c):Tyler loves the numbers 2 and 3 because theyre the only two prime numbers that are adjacent. One of his favorite ways to spend his free time is counting how many factors of 2 and 3 various lists of numbers have (dont make fun of his life choices, different people like different things). But hes found that, as his lists get bigger, hes spending too much time doing math and not enough time enjoying the factors. So hes asked you to write a program that will count these factors of 2 and 3 for him.Write a program that will read in a list of numbers, and after reading each number, output the current count of factors of 2 and 3 seen so far. The list will be terminated by a 0 (zero).Your program should have and use the following function (written by you):// Precondition: value is a positive integer. two_count and// three_count are pointers to ints that hold current counts of how// many factors of 2 and 3 have been seen so far, respectively.// Postcondition: two_count and three_count will be updated to// include counts of 2s and 3s found as factors of value.void update_counts(int value, int* two_count, int* three_count)Sample Run (User input in bold and italics):2So far, there have been 1 factors of 2 and 0 factors of 3.3So far, there have been 1 factors of 2 and 1 factors of 3.6So far, there have been 2 factors of 2 and 2 factors of 3.0See you next time!Sample Run (User input in bold and italics):64So far, there have been 6 factors of 2 and 0 factors of 3.27So far, there have been 6 factors of 2 and 3 factors of 3.36So far, there have been 8 factors of 2 and 5 factors of 3.1So far, there have been 8 factors of 2 and 5 factors of 3.0See you next time!

Program C: Case Fixer (casefixer.c):Andrew has a text file full of titles. However, he doesnt like to use his shift key. Instead, he often uses the capslock key. This would be fine (though extra work for him), except sometimes he forgets to turn it on/off at the right times. As such, his list of titles sometimes end up with the wrong capitalization. Can you help him fix this? And while youre at it, output line numbers, too.Read in the tiles in a text file (casefixer.txt), and output the titles with proper capitalization (to standard output). To be clear, a title is a sequence of printable characters (letters, numbers, and spaces) with no line breaks. Each title is separated by a line break (
). Proper capitalization of a title is the first letter being capitalized and the rest being lower case. (We will ignore any special rules about a or other short words and stick with this simplified definition for this assignment.)Your program should read until the end of the file. The easiest way to do this is to check the return value of fscanf after attempting a read with it. If it returns EOF (a builtin constant), then no character was read because the end of the file was reached (and you should stop).Otherwise, the next character was read (as normal).Your program should have and use the following function (written by you):// Precondition: ch points to the character to process. char_in_word// and line_num point to counters of what their names describe.// Postcondition: returns true if the character was a line break// (meaning following this will be a new line), or false otherwise.// Fixes the character pointed to by ch to have proper case.// Updates the two counters based on this character.int fix_caps(char* ch, int* char_in_word, int* line_num)You may also find it helpful to use the following builtin functions:// Returns the uppercaseversion of c.char toupper(char c)// Returns the lowercaseversion of c.char tolower(char c)Hint: you do NOT need to use anything we havent learned yet (like strings) to do this. Just think about doing this one character at a time. fscanf/scanf with %c will read one character each time, allowing you to process a single character at a time. These can be passed one at a time to fix_caps.casefixer.txt for the below sample:This line has proper caseTHIS LINE HAS IMPROPER CASE this line also has improper casetHE qUICK bROWN fOX jUMPS oVER tHE lAZY dOGSample Run:1 This Line Has Proper Case2 This Line Has Improper Case3 This Line Also Has Improper Case4 The Quick Brown Fox Jumps Over The Lazy DogDeliverables:Please submit three separate .c files for your solutions to these problems via WebCourses bythe designated due date:Program A: averaging.cProgram B: twosandthrees.cProgram C: casefixer.c

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] SOLVED: Assignment #6
$25