The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 314 Weeks Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
HI, Adi10198
Can you also help me with these problems, your programming solution is pretty similar with the things we studied in class and pretty useful.
please and thank you.
cha 5
6. Fuel Economy A fuel-economy study was carried out for five models of cars. Each
car was driven 100 miles, and then the model of the car and the number of gallons
used were placed in a line of the file Mileage.txt. Table 5.11 shows the data for the
entries of the file. Write a program to display the models and their average miles per
gallon in decreasing order with respect to mileage. See Fig. 5.51. The program should
create a dictionary of five items, with a key for each model, and a two-tuple for each
value. Each two-tuple should be of the form (number of test vehicles for the model, total
number of gallons used by the model).
Â
7. U.S. Cities The file Cities.txt contains information about the 25 largest cities in
the United States. Each line of the file has four fields—name,state,population in 2000
(in 100,000s), and population in 2010 (in 100,000s). Write a program that creates a new
file with each line containing the name of a city and its percentage population growth
from 2000 to 2010. The cities should be in decreasing order by their percent population
growth. The first four lines of the file Cities.txt are as follows:
New York,NY,80.1,82.7
Los Angeles,CA,36.9,38.84
Chicago,IL,29.0,28.7
Houston,TX,19.5,22.4
Â
cha 6
1. Guess My Number Write a robust program that randomly selects a number from
1 through 100 and asks the user to guess the number. At each guess the user should
be told if the guess is proper, and if so, whether it is too high or too low. The user
should be told of the number of guesses when finally guessing the correct number.
See Fig. 6.28.
2. Analyze a Poker Hand Write a program using the file DeckOfCardsList.dat that
randomly selects and displays five cards from the deck of cards and determines which
of the following seven categories describes the hand: four-of-a-kind,full house (three cards of one rank, two cards of another rank), three-of-a-kind,two pairs, one pair, or ranks-all-different. See Fig. 6.29. (Hint: Determine the number of different ranks in the hand and analyze each of the four possible cases.)
Â
cha 7
Â
2. Savings Account Write a program to maintain a savings account. The program
should use a class named SavingsAccount with instance variables for the customer's
name and the account balance, and two methods named makeDeposit and makeWithdrawal.
The makeWithdrawal method should deny withdrawals that exceed the balance in the account. See Fig. 7.22.
Â
3. Payroll Write a program that displays the weekly payroll for a company that hires
both salaried and hourly employees. The program should contain a class named
Employee having two subclasses named SalariedEmployee and HourlyEmployee. The
Employee
class should have instance variables for name, rate of pay, and hours worked.
(The rate of pay should be a fixed amount for salaried employees and the hourly wage
for hourly employees.) Each subclass should have a calculatePay method.
After the data for all of the employees has been entered, the program should display
the week's pay for each employee, the number of employees, the number of salaried
employees, the total payroll, and the average number of hours worked by the employees. See Fig. 7.23. The program should use a list of objects.
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly