WordPress.com
Introduction to Computer ScienceSection-BAssignment-5Submission: 16th May, 2015 (until labs are open)Submission path: \\xeon\Spring 2015\ICS B\Course Work\Assignment 5For this assignment, your main should not be doing anything except for calling functions. Make separate functions for input, output etc.Exercise 1:Suppose you have an integer array of 10 numbers (take input from the user). You have to display a histogram chart by showing the number of ‘#’ equal to the value entered in each element of the array raised to the power of its index value in the array (assume the indexes start from 1). Write a function named Histogram for this purpose which will receive an integer array(think about other functions required).You can use built-in power function in your code. For Example: Let’s assume that we have an array of size 4 which has the following values: 5, 4 3 & 1. We make an assumption that our indexes start from 1, so the value 5 is at 1st index. The no. of # to be printed first is 5 ^ 1 = 5. Similarly 4 ^ 2 = 16, 3 ^ 3 = 27 & 1 ^ 4 = 1.5 ##### 4 ################ 3 ########################### 1 # Exercise 2:voidremove_till(char src[], int position, char c);Write a function named remove_till which takes a c-string,an integer position and a character c. The function removes all characters starting from index position and towards the right until char c is encountered in the c-string. If c isnt encountered the function removes all characters from index position till end of the array.Example:Input: string=“helloo! how are you today”, position=8, c=‘y’Output: string=“helloo! ou today”Exercise 3:In the land of Puzzlevania, Aaron, Bob and Charlie had an argument over which of them was the greatest puzzler of all time. To end the argument once and for all, they agreed on a duel to the death. Aaron is a poor shooter and only hits his target with a probability of 1/3. Bob is a bit better and hits his target with a probability of ?. Charlie is an expert marksman and never misses. A hit means a kill and the person hit drops out of the duel.To compensate for the inequities in their marksmanship skills, it is decided that the contestants would fire in turns with Aaron, followed by Bob and then by Charlie. The cycle would repeat until there was one man standing. And that man would be remembered as the greatest puzzler of all time.Write a function to simulate a single shot. It should use the following prototype:void shoot(bool&targetAlive, double accuracy);This would simulate someone shooting at targetAlive with the given accuracy by generating a random number between 0 and 1. If the random number is less than the accuracy then the target is hit and targeAlive should be set to false. For example if Bob is shooting at Charlie, this could be invoked as:shoot(CharlieAlive, 0.5);Here CharlieAlive is a Boolean variable that indicates if Charlie is alive.An obvious strategy is for each man to shoot at the most accurate shooter still alive on the grounds that this shooter is the deadliest and has the best chance of hitting back. Write a second function named startDuel that uses this shoot function to simulate an entire duel using this strategy. It should loop until only one contestant is left, invoking the shoot function with proper target and probability of hitting the target according to who is shooting. The function should return a variable that indicates who won the duel.In your main function invoke the startDuel function 1000 times in a loop, keeping track of how many times each contestant wins. Output the probability that each contestant will win when everyone uses the strategy of shooting at the most accurate shooter alive.Exercise 4:Write a program that asks for users’ height, weight and age then computes clothing sizes according to the formulas:Hat size=weight in pounds divided by height in inches and all that multiplied by 2.9.Jacket size =height times weight divided by 288 and then adjusted by adding 1/8 of an inch for each 10 years over age 30. (Note that the adjustment takes place after full ten years. So there is no adjustment for ages 30 to 39 but 1/8 of an inch are added for age 40.)Waist in inches= weight divided by 5.7 and then adjusted by 1/10 of an inch for each 2 years over age 28. (Note that the adjustment only takes place after a full 2 years. So there is no adjustment for age 29 but 1/10 of an inch is added for age 30).Use function for each calculation. Your program should allow the user to repeat this calculation as often as user wishes.Exercise 5:Write a program that converts from 24-hour notation to 12- hour notation. For example it should convert 14:25 to 2:25 PM. The input is given as two integers. There should be at least three functions, one for input, one to do the conversion and one for output. Record the AM/PM information as a value of type char, ‘A’ for AM and ‘P’ for PM. Thus, the function for doing conversions will have a call-by-reference formal parameter of type char to record whether is AM or PM.(The function will have other parameters as well). Include a loop that lets the user repeat this computation for new input values again and again until the user says he or she wants to end the program.Exercise 6:Given two sets A and B, the union operation gives a new set that contains the elements of both the sets, but no element can be repeated. So given that A={1,4,6,7,9} and B={7,9,10,15} then C=AUB (where U denotes the union operation)={1,4,6,7,910,15}. Another important operation over sets is called intersection. For the sets A and B given above the set D=A∩B (where ∩ denotes the intersection of sets) = {7,9}. You have to write program using arrays to represent sets that implements these set operations. Use constint size1=5 for size of first set and constint size2=8 for size of second set. Take inputs of sets from user and implement following functions:voidInputSet (int A[], int B[]); //take input from users for arrays A and Bvoid Union(int A[], int B[], int result[]); //take union of array A and B and store result in third array resultvoid Intersection(int A[], int B[], int result[]); //take intersection of array A and B and store result in third array resultvoidPrintSet(int A[]); //to print elements of array AYour main function structure should be as follows:int main(){//Variables declaration and initializations - A, B, U, I are arraysInputSet (A, B);Union (A, B, U);PrintSet(U);Intersection (A, B, I);PrintSet (I);} ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- subjugation ii insurrection by fel
- spirit walker 2 shadow walker by fel
- pedophilia empire
- the west virginia state museum
- assume no peace discharge debt
- a glimpse of eternity divine revelations
- a system of morality which is based on relative emotional
- news from discovery channel
- christianity the deadliest poison and zen the antidote
Related searches
- wordpress passing data between pages
- wordpress business templates
- wordpress rss feed not working
- wordpress jquery is not defined
- create wordpress blog
- wordpress roles editor
- wordpress full rss feed
- wordpress rss feed settings
- wordpress rss feed plugin
- wordpress display rss feed
- wordpress rss feed link
- wordpress rss feed to post