





























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A variety of programming fundamentals topics, including input validation, array manipulation, function implementation, and problem-solving exercises. It presents several programming challenges and their solutions, covering areas such as chips and salsa sales tracking, positive vs. Negative number counting, temperature variation analysis, magic square creation, price calculation, exam grading, lottery simulation, vector modification, baseball team data analysis, name searching, gas price tracking, markup calculation, sales division comparison, falling distance calculation, coin tossing, present value computation, population modeling, heating energy and time estimation, prime number listing, multiplication table generation, distance traveled, population growth prediction, queue waiting time estimation, random number guessing games, student line-up management, array element addressing, test score processing, function parameter manipulation, and more.
Typology: Exams
1 / 37
This page cannot be seen from the preview
Don't miss anything!
Largest and Second Largest Even Numbers
Rainfall Statistics
Chips and Salsa Write a program that lets a maker of chips and salsa keep track of sales for five differ- ent types of salsa: mild, medium, sweet, hot, and zesty. The program should use two parallel 5-element arrays: an array of strings that holds the five salsa names, and an array of integers that holds the number of jars sold during the past month for each salsa type. The salsa names should be stored using an initialization list at the time the name array is created. The program should prompt the user to enter the number of jars sold for each type. Once this sales data has been entered, the program should produce a report that displays sales for each salsa type, total sales, and the names of the highest selling and lowest selling products. Input Validation: Do not accept negative values for number of jars sold.
Temperature Variation The weather service center of a certain city records the highest temperature, lowest temperature, and humidity of each day. Write a program that maintains three arrays and initializes the highest temperature, lowest temperature, and humidity in the three arrays, for each day of the first 10 days of a month. The program should then create a weather report that includes the following information:
Lo Shu Magic Square The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown in Figure 7-19. The Lo Shu Magic Square has the following properties:
plu: an array of price lookup codes (PLU) for products at a grocery store
Your program should store the correct answers shown above in an array. It should ask the user to enter the student’s answers for each of the 20 questions, and the answers should be stored in another array. After the student’s answers have been entered, the program should display a message indicating whether the student passed or failed the exam. (A student must correctly answer 15 of the 20 questions to pass the exam.) It should then display the total number of correctly answered questions, the total number of incorrectly answered questions, and a list showing the question numbers of the incorrectly answered questions. Input Validation: Only accept the letters A, B, C, or D as answers. file is also in the Chapter 07 source code folder.) The program should determine the number of questions that the student missed, then display the following:
A Graded Social Network The goal of a social network is to connect people. In an early attempt, people were asked to grade each other on a scale of 1 to 10. An algorithm would decide who was friend with whom. The idea was that anyone whom someone graded a 5 or more would be that person’s friend. In a certain experiment with three people, this was the input:
John 10 4 7 Mike 3 2 4 Mary 10 10 10 It was expected that people would be each other’s friends, but it turned out that this was not the case. In this case, for example, Mike indicated that he had no friends at all. Because of this and various other obvious reasons, this social network failed. However, it may still be interesting to write a program to repeat the experiment. The program should use a string array of length 5 to hold the names of the people in the network, and five int arrays to hold their friend scores. The program should let the user enter five names and five scores per person. It should then display the number of friends per person and their names.
the following shows the lottery array and the user array with sample numbers stored in each. There are two matching digits (elements 2 and 4). Lottery array: 7 4 9 1 3 User array: 4 2 9 7 3 The program should display the random numbers stored in the lottery array and the number of matching digits. If all of the digits match, display a message proclaiming the user as a grand prize winner. vector Modification Modify the National Commerce Bank case study presented in Program 7-23 so pin1, pin2, and pin3 are vectors instead of arrays. You must also modify the testPIN func- tion to accept a vector instead of an array.
World Series Champions If you have downloaded this book’s source code, you will find the following files in this chapter’s folder:
When the user enters the name of a team, the program should step through the array or vector counting the number of times the selected team appears.
loop that does the following:
1994 Gas Prices In the student sample programs for this book, you will find a text file named 1994_ Weekly_Gas_Averages.txt. The file contains the average gas price for each week in the year 1994 (There are 52 lines in the file. Line 1 contains the average price for week 1, line 2 contains the average price for week 2, and so forth.) Write a program that reads the gas prices from the file into an array or a vector. The program should do the following:
Markup Write a program that asks the user to enter an item’s wholesale cost and its markup percentage. It should then display the item’s retail price. For example: If an items wholesale cost is 5.00 and and its markup percentage is 100 percent, then items retail price is 10.0. If an items wholesale cost is 5.00 and and its markup percentage is 50 percent, then items retail price is 7.50. The program should have a function named calculateRetail that receives the wholesale cost and the markup percentage as arguments and returns the retail price of the item. Input Validation: Do not accept negative values for either the wholesale cost of the item or the markup percentage. Rectangle Area—Complete the Program If you have downloaded this book’s source code, you will find a partially written pro- gram named AreaRectangle.cpp in the Chapter 06 folder. Your job is to complete the program. When it is complete, the program will ask the user to enter the width and length of a rectangle, then display the rectangle’s area. The program calls the following functions, which have not been written:
Winning Division Write a program that determines which of a company’s four divisions (Northeast, Southeast, Northwest, and Southwest) had the greatest sales for a quarter. It should include the following two functions, which are called by main:
Coin Toss Write a function named coinToss that simulates the tossing of a coin. When you call the function, it should generate a random number in the range of 1 through 2. If the random number is 1, the function should display “heads.” If the random number is 2, the function should display “tails.” Demonstrate the function in a program that asks the user how many times the coin should be tossed, then simulates the tossing of the coin that number of times. Present Value Suppose you want to deposit a certain amount of money into a savings account and then leave it alone to draw interest for the next 10 years. At the end of 10 years, you would like to have $10,000 in the account. How much do you need to deposit today to make that happen? You can use the following formula, which is known as the present value formula, to find out: P=
The terms in the formula are as follows:
Write a program that has a function named presentValue that performs this calcula- tion. The function should accept the future value, annual interest rate, and number of years as arguments. It should return the present value, which is the amount that you need to deposit today. Demonstrate the function in a program that lets the user experi- ment with different values for the formula’s terms. Future Value Suppose you have a certain amount of money in a savings account that earns compound monthly interest, and you want to calculate the amount that you will have after a spe- cific number of months. The formula, which is known as the future value formula, is F= P X (1+i)^2 The terms in the formula are as follows: