This assignment is to give you practice using enums, string variables, and string functions. In order to get full credit for the program you must use these three topics.
You are to write a program that will read a series of names of people from a data file that has been created with extra blank spaces and reformat the names into a standardized format.
The datafile is mp6names.txt. It is arranged with the information for one person on each line. The first character on the line will be either ‘M’ or ‘F’ indicating the gender of the person, and the second character will be either ‘M’, ‘S’, or ‘D’ indicating married, single or divorced. You may assume that there will be no bad data here. The remainder of the line is the person’s name in the form:
Last_name, First_name Middle_Initial.
Note that there will always be a comma immediately after the last name and, if the person has middle initial, it will always be followed by a period. However, there could be any number of blank spaces in between each part of the name and some people do not have middle initial.
Your task is to clean up the name and print it out in the standard format, e.g. Mr. Bill T. Jones with the appropriate title and exactly one space between each part of the name.
You are REQUIRED to use functions, enums, string variables and string functions in the solution to this problem. Define an enum for the Marital Status of the person (with the values SINGLE, MARRIED and DIVORCED) and write a function that reads in the character from the file and returns the appropriate enum value.
Read the name from the file into a string variable and write another function that uses the functions of the string class (e.g. find(), substr() etc.) to clean up the name and create a new string variable containing the name in the new format.
Finally, add the appropriate title to the name and print it out. All males will have the title “Mr.” – married females will have “Mrs.” and single or divorced females will have “Ms.”
Continue doing this until the end of file is reached. Your output must include the original name as read from the file followed by the new name in the standardized format. For formatting purposes you may assume that no name will have more than 30 characters.
This is just a SUGGESTED method and for each step you may want to include output for debugging purposes to insure that your program is working correctly. Feel free to design your own modules as you like. A sample output from the first few lines of the data file follows:
Original
name
Standardized name
Bach, Johann
S. Mr. Johann S.
Bach
Curie, Marie
A.
Mrs. Marie A. Curie
Parker, Alice
M.
Ms. Alice M. Parker
In: Computer Science
Write a C program that reads a file and reports how many lines, words, and characters appear in it. For the purpose of this program, a word consists of a consecutive sequence of any characters except white space characters. For example, if the file lear.txt contains the following passage from King Lear,
Poor naked wretches, wheresoe’er you are,
That bide the pelting of this pitiless storm,
How shall your houseless haeds and unfed sides,
Your loop’d and window’d raggedness, defend you
From seasons such as these? O, I have ta’en
Too little care of this!
Your program should be able to generate the following sample run:
File: lear.txt
Lines: 6
Words: 43
Chars: 210
In: Computer Science
in c++ language
This assignment is to give you practice using structs and sorting.
In competitive diving, each diver makes dives of varying degrees of difficulty. Nine judges score each dive from 0 through 10 in steps of 0.5. The difficulty is a floating-point value between 1.0 and 3.0 that represents how complex the dive is to perform. The total score is obtained by discarding the lowest and highest of the judges’ scores, adding the remaining scores, and then multiplying that total by the degree of difficulty. Write a program to score each of the dives, using the following input and output specifications, and determine the winner of the competition.
Input:
Create the file m7divers.txt using the data given at the end.
The first line contains an integer for the number of divers in
the competition and subsequent lines contain:
Diver’s name (10 characters max, no blanks included), difficulty
(double), and judges’ ratings (nine doubles). There is one line of
data for each diver.
Example file: (This is not the data to use)
| Anne | 2.0 | 8.0 | 8.5 | 8.5 | 8.5 | 9.0 | 9.0 | 9.0 | 9.5 | 9.5 | 124.0 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Sarah | 1.6 | 7.0 | 7.5 | 8.0 | 8.0 | 8.0 | 8.5 | 8.5 | 8.5 | 9.0 | 91.2 |
Output:
The name and difficulty, followed by the scores sorted into increasing order, in tabular form with appropriate headings along with the earned total points for that dive.
Example for sample data above
| NAME | DIFF | SORTED SCORES | POINTS | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Anne | 2.0 | 8.0 | 8.5 | 8.5 | 8.5 | 9.0 | 9.0 | 9.0 | 9.5 | 9.5 | 124.0 |
| Sarah | 1.6 | 7.0 | 7.5 | 8.0 | 8.0 | 8.0 | 8.5 | 8.5 | 8.5 | 9.0 | 91.2 |
At the end of the table, print out the name of the winner of the
competition (the person with the highest points) and his/her final
score.
Hint: Use functions to modularize your program.
Use this data for your input file. download the data from the attachment.
| NAME | DIFF | SORTED SCORES | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Anne | 2.0 | 8.0 | 8.5 | 8.5 | 8.5 | 9.0 | 9.0 | 9.0 | 9.5 | 9.5 |
| Sarah | 1.6 | 7.0 | 7.5 | 8.0 | 8.0 | 8.0 | 8.5 | 8.5 | 8.5 | 9.0 |
| Deborah | 2.3 | 9.0 | 9.0 | 9.5 | 10.0 | 10.0 | 9.5 | 9.5 | 9.5 | 9.5 |
| Kathryn | 2.4 | 9.0 | 9.0 | 9.0 | 9.5 | 9.5 | 9.5 | 9.0 | 8.0 | 8.5 |
| Martha | 2.7 | 9.0 | 9.0 | 9.5 | 9.5 | 9.0 | 8.5 | 8.5 | 8.5 | 8.5 |
| Elizabeth | 2.9 | 8.0 | 8.0 | 7.5 | 8.5 | 8.5 | 8.0 | 8.0 | 7.5 | 8.5 |
| Tina | 2.5 | 8.5 | 8.5 | 8.5 | 8.5 | 8.5 | 8.5 | 8.5 | 8.5 | 8.5 |
In: Computer Science
Write a program in PYTHON which:
*Defines the following 5 functions:
whoamI()
This function prints out your name and PRINTS OUT any programming course you have taken prior to this course.
isEven(number)
This function accepts one parameter, a number, and PRINTS OUT a message telling if the numberer is even or odd. Keep in mind that a number is even if there is no remainder when the number is divided by two.
printEven(number)
This function accepts one parameter, a number, and PRINTS OUT all even values from 2 thru this number.
sumUp(number)
This function accepts one parameter, a number, and RETURNS the sum of ALL values from 1 up to this number
howmanyDigits(number)
This function accepts one parameter, a number, and RETURNS the number of digits contained in the value. (for example, if the value was 475, the function would return a 3. Hint: the simplest way to do this is to convert the number to a string .. then the length is accessible
* follows the function definition with main process statements which:
1.) calls the 'whoamI' function to that the program begins by outputting uses information
2.) prompt the user for a positive int and store it
If the user does not enter a valid number, reprompt. Continue this until a valid value
has been entered.
3.) present the user with 4 choices:
-find out if the number is even or odd
- printout all even values up to the number
-output the sum of all values from one to the number
- output the number of digits in the number
4.) Carry out the user’s choice. Be sure to call one of the functions that you have defined to do this.
If you wish you may put the main statements in a loop that repeats until the user chooses to exit.
In: Computer Science
Discuss several categories of common end-user technology problems.
Provide examples of problem-solving processes applied to typical support problems.
In: Computer Science
This Code Is Supposed To Be Performed In JAVA
1.) Create an abstract class DiscountPolicy. It should have a single abstract method computeDiscount that will return the discount for the purchase of a given number of a single item. The method has two parameters, count and itemCost. Create a driver class that tests this class and provide the UML.
2.) In a separate program, define DiscountPolicy as an interface instead of the abstract class. Create a driver class that tests this class and provide the UML.
Perform The Following
1.) Create an abstract class DiscountPolicy with a single abstract method computeDiscount that will return the discount for the purchase of a given number of a single item.
2.) Create a driver class
3.) Create an interface class DiscountPolicy with a single abstract method computeDiscount that will return the discount for the purchase of a given number of a single item.
4.) Create a driver class or use the same driver class that you created earlier
In: Computer Science
1. Enhance Binary System Conversion program with Lab05.2 Addition Function Write a program that accepts two positive binary number in string and perform the addition with Lab05.2 function enhance in a way can accept binary string in addition to decimal string (use input parameter to control the base2 or base10 addition) and output the as binary string. (Optional: Demonstrate 8 bits and 16 bits in length as inputs.) // the example function prototype for addition function below where accepting two numbers, m, and base as input; output the addition result as string type as return value; base should be 2 or 10 as required. string addFunction(string numberA, string numberB, int m, int base); Requirement: C++ programing; program an addition algorithm function that can both accept binary and decimal addition; convert each other if necessary. ................................................................................................................................................................................................................
Requirement:
1. Write a string addFunction that both can accept two positive binary numbers and decimal numbers in string.
2. The example function prototype for addition function below where accepting two numbers,m, and base as input; output the addition result as string type as return value; base should be 2 or 10 as required.
3. Output needs as binary string.
4. Example for String addFuntion(string numberA, string number B, int m, int base).
Program language: C++
In: Computer Science
Use the substitution method to prove the solutions for the following recurrences:
|
Recurrence |
Solution |
|
|
1 |
T(n) = T(n-1) + n |
O(n2) |
|
2 |
T(n) = T(n/2) + 1 |
O(lgn) |
|
3 |
T(n) = T(n/2) + n |
ϴ(nlgn) |
|
4 |
T(n) = 3T(n/2) + n |
O(nlg(3)). |
|
5 |
T(n) = 2T(n/2) + n2 |
O(n2) |
|
6 |
T(n) = 4T(n/2 + 2) + n |
O(n2) |
|
7 |
T(n) = 2T(n – 1) + 1 |
O(2n) |
|
8 |
T(n) = T(n – 1) + T(n/2) + n |
O(2n) |
|
9 |
T(n) = 4T(n/2) + cn. |
ϴ(n2) |
In: Computer Science
|
Write a C++ program that declares three one-dimensional arrays named miles, gallons and mpg. Each array should be capable of holding 10 elements. In the miles array, store the numbers 240.5, 300.0 189.6, 310.6, 280.7, 216.9, 199.4, 160.3, 177.4 and 192.3. In the gallons array, store the numbers 10.3, 15,6, 8.7, 14, 16.3, 15.7, 14.9, 10.7 , 8.3 and 8.4. Each element of the mpg array should be calculated as the corresponding element of the miles array divided by the equivalent element of the gallons array: for example mpg[0]=miles[0]/gallons[0]. Use pointers when calculating and displaying the elements of the mpg array. |
In: Computer Science
In: Computer Science
Suppose the RTT between your host and marist.edu is 10 ms, between your host and nyu.edu is 20 ms, and between your host and albany.edu is 30 ms.
Assume parallel transmissions are not considered in this problem, that is, objects are obtained one after another.
a) How long does it take to load the entire webpage with HTTP 1.0?
b) How long does it take to load the entire webpage with HTTP 1.1?
In: Computer Science
In: Computer Science
In java. Determine the value of each of the following expressions. (Format your answer with two decimal places.) a. Math.abs(-4) b. Math.abs(10.8) c. Math.abs(-2.5) d. Math.pow(3.2, 2) e. Math.pow(2.5, 3) f. Math.sqrt(25.0) g. Math.sqrt(6.25) h. Math.pow(3.0, 4.0) / Math.abs(-9) i. Math.floor(28.95) j. Math.ceil(35.2)
In: Computer Science
[15] Create a program called StreamingWords.java that modifies the StreamingIntegers.java from Task 1. The program should be able to do the following: JAVA
accepts user input. User inputs can be under the following forms:
one or more words, separated by white space.
User can provide multiple inputs (each input is completed after user hits Enter)
To stop inputting data, user will enter END then hit Enter.
reads inputs from users into a queue data structure. Each data element in the queue contains one sentence (from whence user starts typing until they hit Enter)
Once users finish entering input (END has been read), the program should begin remove the queue from the front, printing out the data elements in the queue.
The data elements should be printed out already sorted based on the number of words each element contains, regardless of the order of arrival or the total length of the characters. Each data element is to be printed on one line, and words within a data element are separated by a single white space.
In: Computer Science
A program called i2b.c was implemented with the intention to provide a binary representation of an integer. Unfortunately, the implementation has the following limitation:
Modify the existing source code of i2b.c such that:
PROGRAM BELOW
#include <stdio.h>
#define N 32
int main(int argc, char *argv[]) {
int n = 12345;
int binRep[N];
int i;
for (i = 0; i < N; i++) {
binRep[i] = 0;
}
i = 0;
while (n > 0) {
binRep[i] = n % 2;
n = n / 2;
i++;
}
for (i = N - 1; i >= 0; i--) {
printf("%d", binRep[i]);
}
printf("\n");
return 0;
}
In: Computer Science