代写五个基础C++练习题,从Word Separation Problem到Multipurpose Problem.
Exercise #1 Word Separation Problem
Write a program that accepts as input a sentence in which all words are run
together, but the first character of each word is uppercased. Convert the
sentence to a string in which the words are separated by spaces and only the
first word starts with an uppercase character.
Sample output:
Enter a sentence: FourScoreAndSevenYearsAgo
Four score and seven years ago
Save your solution in a file named separate.cpp.
Exercise #2 Date Formatting Problem
Write a program which reads in a string from the user containing a date in the
format mm/dd/yyyy. It should print the date in the form MONTH DD,YYYY.
Sample output:
Enter a date (mm/dd/yyyy): 03/12/2015
March 12, 2015
Save your solution in a file named formatting.cpp.
Exercise #3 Pointer Problem
Write a function that accepts an array of integers and the array’s size as
arguments. The function should create a copy of the array, except that the
values should be reversed in the copy. The function should return a pointer to
the new array. Write a main function which uses this function and asks users
for values in an array, outputting the reversed array afterwards.
Sample output:
How many numbers do you have in your array? 3
Enter value #1: 51
Enter value #2: 16
Enter value #3: 97
97 16 51
Save your solution in a file named pointer.cpp.
Exercise #4 Inventory Problem
Write a program that simulates inventory bins in a warehouse. Each bin holds a
number of the same type of parts. The program should use a structure that
keeps the following data:
- Description of the part kept in the bin
- Number of parts in the bin
The program should have an array of ten bins initialized with the following
data:Part Description Number of Parts in the Bin
Valve | 10
Bearing | 5
Bushing | 15
Coupling | 21
Flange | 7
Gear | 5
Gear Housing | 5
Vacuum Gripper | 25
Cable | 18
Rod | 12
The program should have the following functions:
- addParts – a function that increases a specific bin’s count by a specified number
- removeParts – a function that decreases a specific bin’s count by a specified number When the program runs it should repeat a loop that performs the following steps:
- The user should see a list of what each bin holds and how many parts are in each bin
- The user can either chose to quit the program or select a bin
- When a bin is selected, the user can either add or remove parts from it
- The loop repeats, showing the updated bin data on the screen
Input validation: no bin can hold more than 30 parts, so don’t let the user
add more than a bin can hold. Also don’t accept negative values for the number
of parts being added or removed.
Optional: you may use C++ objects instead of structs to represent an inventory
bin.
Save your solution in a file named inventory.cpp.
Exercise #5 Multipurpose Problem
Write a program that calculates pay for either hourly paid workers or salaried
workers. Hourly paid workers are paid their hourly pay rate times the number
of hours worked. Salaried workers are payed their regular salary plus any
bonus they may have earned. The program should declare two structures for the
following data:
- Hourly Paid
- HoursWorked
- HourlyRate
- Salaried
- Salary
- Bonus
The program should also declare a structure with two members. Each member
should be a structure variable: one for the hourly paid worker and another for
the salaried worker.
The program should ask the user whether he or she is calculating pay for an
hourly paid worker or a salaried worker. Regardless of what the user selects,
the appropriate members of the struct will be used to store the data that will
be used to calculate the pay.
Input Validation: do not accept negative numbers. Do not accept values greater
than 80 for hours worked.
Optional: you may use C++ objects in place of structs to represent salaried
and hourly employees
Save your solution in a file named multipurpose.cpp.