Question
Write a function Zero that will take a number as a parameter and return the number of zeroes and the number of remaining digits in
Write a function Zero that will take a number as a parameter and return the number of zeroes and the number of remaining digits in the number (two values). Print the returned value in the main i.e. Num=2021800, Zeroes= 3, Other Digits=4. Problem 2: (Computer-Assisted Instruction) Problem 2.1 The use of computers in education is referred to as computer-assisted instruction (CAI). Write a program that will help an elementary school student learn multiplication. Use the rand function to produce two positive one-digit integers (i.e. 6 and 7). The program should then prompt the user with a question, such as How much is 6 times 7? The student then inputs the answer. Next, the program checks the students answer. If its correct, display the message "Very good!" and ask another multiplication question. If the answer is wrong, display the message "No. Please try again." and let the student try the same question repeatedly until the student finally gets it right. A separate user-defined function should be used to generate each new question. This function should be called once when the application begins execution and each time the user answers the question correctly. Problem 2.2 One problem in CAI environments is student fatigue. This can be reduced by varying the computers responses to hold the students attention. Modify the program of Problem 2.1 so that various comments are displayed for each answer as follows: Possible responses to the correct answer: Very good! Excellent! Nice work! Keep up the good work! Possible responses to an incorrect answer: No. Please try again. Wrong. Try once more. Don't give up! No. Keep trying. Use random-number generation to choose a number from 1 to 4 that will be used to select Page 2 of 6 one of the four appropriate responses to each correct or incorrect answer. Correct answer response must be generated in PositiveResponse function and wrong answer response must be generated in NegativeResponse function. Use a switch statement to issue the responses. Problem 2.3 More sophisticated computer-assisted instruction systems monitor the students performance over some time. The decision to begin a new topic is often based on the students success with previous topics. Modify the program of Problem 2.2 to count the number of correct and incorrect responses typed by the student. After the student types 10 answers, your program should calculate the correct percentage. If the percentage is lower than 75%, display "Please ask your teacher for extra help.", then reset the program so another student can try it. If the percentage is 75% or higher, display "Congratulations, you are ready to go to the next level!", then reset the program so another student can try it. Page 3 of 6 Problem 3: Write two functions having the same name Add and both take two parameters. When called from main, they will print I have been called n times where n is the number of calls, they have received from main, and will return the sum of arguments passed. Note: Keep taking input until the user enters -1. Example Output: Add(12,12); Sum = 24, I have been called 1 time Add(45,1254); Sum = 1299, I have been called 2 times Add(45.89,12.45); Sum = 58.34, I have been called 1 time Add(1,15); Sum = 16, I have been called 3 times (This was dummy output; you are supposed to take input from the user and add them until the user enters -1) Problem 4: Write a C++ Program to Merge Two Files into a Single file using File Handling. First File should contain half of your intro and the second file should contain the remaining half of your intro. The resulting Third file will contain your full intro. Full into Should contain, your name, father name, city, roll number, email, hobbies, favorite movies, favorite Subject, etc. Note: Make the program generic, it should work either I store whole into one line or multiple lines. Example Input Files: Bio1.txt Bio2.txt Name XYZ Father Name XYZ City XYZ Roll Number XYZ Email XYZ Hobbies Favorite Movies XYZ Favorite Subject Example Output File: Name XYZ Father Name XYZ City XYZ Roll Number XYZ Email XYZ Hobbies Favorite Movies XYZ Favorite Subject Page 4 of 6 Problem 5: Implement a number counting program. Your program will consist of two different functions, Write into File Read from File Write into File will take input from the user (as long as the user doesnt enter -1) and will keep on writing this data into a file named Numbers.txt. Input from the user will be a number from 0-9 and no other input will be accepted (display error if another input is given by the user). Read from File will read the data from Numbers.txt and then count the occurrence of every digit in the file and write it into another text file named Count_Frequency.txt. For example, if the file contains the following data, Then the following will be written into the Count_Frequency.txt file, Count of 0: 2 Count of 1: 2 Count of 2: 2 Count of 3: 2 Count of 4: 0 Count of 5: 2 Count of 6: 2 Count of 7: 0 Count of 8: 1 Count of 9: 2 1 2 0 3 0 5 1 6 9 8 9 6 2 3 5 Page 5 of 6 Problem 6: There are n bikes, and each can cover 100 km when fully fueled. What is the maximum amount of distance you can go using n bikes? You may assume that all bikes are similar, and a bike takes 1 liter to cover 1 km. You have n bikes and using one bike you can only cover 100 km. so if n bikes start from the same point and run simultaneously you can go only 100 km. Lets think a bit differently, trick is when you want to cover the maximum distance, you should always try to waste minimum fuel. Minimum wastage of fuel means to run a minimum number of bikes. Instead of the parallel running of n bikes, you can think of serially running them. That means if you transfer some amount of fuel from the last bike to other bikes and throw the last bike i.e., dont run the last bike after a certain point. But the question is, after what distance the fuel transfer must be done so that the maximum distance is covered, and the fuel tank of the remaining bikes do not overflow. Let us take the following base cases and then generalize the solution. Base Case 1: There is one bike: This is simple, we can cover 100 km only. Base Case 2: There are two bikes: What is the maximum distance we can cover when there are 2 bikes? To maximize the distance, we must drop the second bike at some point and transfer its fuel to the first bike. Let us do the transfer after x km. Total distance covered = Distance covered by 100 ltr in first bike + Distance covered by fuel transferred from the first bike. The remaining fuel in the second bike is 100 x. If we transfer this much fuel to the first bike, then the total distance would become 100 + 100 x which is 200 x. So, our task is to maximize 200-x. The constraint is, 100 x must be less than or equal to the space created in the first bike after x km, i.e., 100 x <= x. The value of 200 - x becomes maximum when x is minimum. The minimum possible value of x is 50. So, we can travel 150 km. Base Case 3: There are three bikes: Let the first transfer is done after x km. After x distance, all bikes contain the 100 - x amount of fuel. If we take 100 - x amount of fuel from 3rd bike and distribute it among 1st and 2nd bike so that fuel tanks of 1st and 2nd bikes get full. So 100-x <= 2*x; or, x=33.333 so we should transfer the remaining fuel of the third bike and distribute that amount of fuel among the 1st and 2nd bike after exactly 33.33 km. Let us generalize it. If we take a closer look at the above cases, we can observe that if there are n bikes, then the first transfer is done (or a bike is dropped) after 100/n km. To generalize it more, when we have x liter remaining fuel in every bike and n remaining bikes, we drop a bike after x/n km. Your program must have the following functions Input function for taking input (input is number of bikes, and amount of fuel (lets say Page 6 of 6 100 initially)) Output function (display the max distance covered) Double MaxDistance(int &n, int fuel) Example Output: The maximum distance possible with 5 bikes is 1141.666667.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started