Program A: Voting Machine (voting.c):Voting with slips of paper is so archaic! So lets write a program that will manage voting for us. But lets take it one step further: lets make sure that each voter only votes once.The program should input a number, N, the number of IDs that are allowed to vote. IDs in this program are the numbers 0 through N1.The program will then prompt for votes from users. In order to place a vote, a user must enter first their ID number and then their vote. The possible votes are A, B, C, and D. If an ID number that has already voted is entered, then they should not be allowed to vote. If ID number 1 is entered, then the voting is over and the program should end, outputting the winner. You may assume that all inputs will be within the bounds specified above you will not be required to check for invalid IDs, votes, etc. You may also assume that a tie will never occur at the end of all votes being added.You may write any functions you find useful in this program, but you are not required to have any for this program.Sample Run (user input in bold and italics):4What is your ID?1Welcome 1, which vote would you like to place?AYou have successfully voted for A.What is your ID?2Welcome 2, which vote would you like to place?BYou have successfully voted for B.What is your ID?1You have already voted. You cannot vote again.What is your ID?0Welcome 0, which vote would you like to place?AYou have successfully voted for A.What is your ID?1A wins with 2 votes!Program B: Manual Sorting (manualsorting.c):Evan claims to know how to sort lists of integers using only swap operations. You dont believe him, so you want to write a program to test his claim.First, read in an integer, N, the number of numbers in the list. Then read in N numbers, the numbers in the list in its initial order. Following this will be a list of pairs of numbers. Each pair of numbers will be distinct from the other in the pair, and will be between 0 to N1(inclusive).These are Evans swap indices. Apply each of these swaps to the array, in the order they are given. A swap of two indices of an array means that the values at each index are swapped such that they are now each at the opposite location. If at any time the array becomes sorted (from smallest to largest), say so. If the array ever becomes unsorted after being sorted, indicate this as well. The final line will contain two integers: 11.This indicates Evan thinks he is done sorting the array. Output a message reporting if he was successful or not.Your program should have and use the following function (written by you):// Precondition: array will be an array of integers of length length.// Postcondition: returns true if the array is in sorted// (nondecreasing) order, or false otherwise.int is_sorted(int array[], int length)It is also recommended that you use the swap function discussed in class.Hint: this problem would be a really good place to use the print_int_array function suggested in class for debugging, since you cant see whats happening with the array using the required output. Even if your output is correct, it is a good idea to verify your program is actually doing what you expect it to. Just dont forget to remove that extra output before you submit.Sample Run (User input in bold and italics):3 2 1 3What is the next swap?1 2What is the next swap?1 2What is the next swap?0 1Evan has sorted the array.What is the next swap?0 1Evan has unsorted the array.What is the next swap?11Evan has failed!Sample Run (User input in bold and italics):41 1 1 2What is the next swap?2 3Evan has unsorted the array.What is the next swap?2 0What is the next swap?0 3Evan has sorted the array.What is the next swap?11Evan was right!Program C: Range Minimum (rangemin.c):We want to write a program to make it easy for us to keep track of the smallest value in a range of indices (locations) in a list. We also want to be able to update ranges within the list.Write a program that inputs a series of these actions.Your program should first create an array of size N, where N is an integer read from the user.This array should start off with values all set to 0. Your program should then repeat the following process. First, read in a character from the user. If this character is an E, then end the program. If this character is an A, then it should read 3 integers to follow, L, H, and V. It should then increase the value of all locations in the array from L to H (L <= H) by V. If thecharacter was a M, it will be followed by only two integers, L and H. Your program should in this case output the minimum value currently in the array between indices L and H (inclusive).You may assume that all input values are within their specified bounds.Your program should have and use the following functions (written by you):// Precondition: low <= high. low = 0. high < size of array.// Postcondition: the value in each index of array between low and// high (inclusive) will be increased by amount.void increment_range(int array[], int low, int high, int amount)// Precondition: low <= high. low = 0. high < size of array.// Postcondition: returns the smallest value in the array between// index low and high (inclusive).int get_range_min(int array[], int low, int high)Hint: this is another program where you may find it very useful to have a function that prints out your array for debugging, since you cant directly see it. As usual, though, make sure theres no debugging output left over when you submit.Sample Run (User input in bold and italics):4A 0 3 10M 0 3The minimum value currently in the range [0,3] is 10.A 0 0 5M 0 3The minimum value currently in the range [0,3] is 10.A 0 1 6A 3 3 2M 1 3The minimum value currently in the range [1,3] is 4.M 2 3The minimum value currently in the range [2,3] is 8.M 0 0The minimum value currently in the range [0,0] is 9.EDeliverables:Please submit three separate .c files for your solutions to these problems via WebCourses bythe designated due date:Program A: voting.cProgram B: manualsorting.cProgram C: rangemin.c
Programming
[Solved] SOLVED:Assignment #7
$25
File Name: SOLVED:Assignment_#7.zip
File Size: 188.4 KB
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.