Specification
The program should repeatedly prompt the user to enter a string of no more than 20 characters. The program will end when the user types in DONE (all caps). Use fgets to get input from the user.
Because fgets leaves the newline character on the string, the program should trim off the newline by replacing it with the null character, effectively shortening the string. Use strchr to locate the newline.
The program will use the input to build up a longer string. You may assume this string will be no longer than 1000 characters. The user input is compared to the longer string and then takes action as follows:
After each user input, display the longer string.
Sample Run
Here's a sample of how the program would work. I've shown user input in bold, just to help it stand out. Your program won't use any special typography.
Enter a string: hello hello Enter a string: world hello world Enter a string: bye bye hello world Enter a string: cat bye hello world cat Enter a string: worl bye hello world cat Enter a string: beep beep bye hello world cat Enter a string: bingo beep bye hello world cat bingo Enter a string: DONE beep byte hello world cat bingo
Let's analyze this one input at a time.
Please note that the program is not putting the words in alphabetic order. It's actually doing something simpler than sorting.
In: Computer Science
Program must be in C
Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate in two different arrays.
The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate.
Your program should also output the winner of the election.
Example (Letters and numbers with underscore indicate an input):
Enter candidate's name and the votes received by the candidate.
Johnson 5000
Miller 4000
Duffy 6000
Robinson 2500
Asthony 1800
Candidate Votes Received % of Total Votes
--------- -------------- ----------------
Johnson 5000 25.91
Miller 4000 20.73
Duffy 6000 31.09
Robinson 2500 12.95
Asthony 1800 9.33
Total Votes: 19300
The Winner of the Election is: Duffy
In: Computer Science
Write a Python program that simulates a restaurant ordering system where it stores multiple orders of a dish and the price for each order stored into a list. The program will then print the receipt which includes list of orders and their price along with the subtotal before tax, the tax amount, and the final total. Also include tip suggestions for 10%, 15% and 20%. Use the format specifiers to make the price line up and the tip only 2 decimal points.
Example:
Welcome to No 2. Kitchen
Order
Lt. Tso Chicken $ 17.50
Half Century Eggs $ 2.50
Durian ice cream $ 5.00
=========================
Subtotal $ 25.00
Tax (7%) $ 1.75
=========================
Total $ 26.75
Tip suggestion
10% : $2.67
15% : $4.01
20% : $5.35
In: Computer Science
In: Computer Science
- Part 2 – 4 Desk Checking Exercises – these are 3 programs (pseudocode) that are working and 1 program (Python). Explainthe intent of the pseudocode / program. If you use test data, note the test data. . You are NOT trying to find mistakes.
What does this do? Desk
Checking #2: Explain the intent of this
pseudocode. Be as specific as possible.
List the data you use as the example data.
|
Use this textbox to explain the pseudocode/ code intent. Include any test data used: |
start
guess number between 1 and 100
while guess is not correct
if guess is too high
guess a number lower than the previous guess
else
guess a number higher than the previous guess
endif
endwhile
player wins
stop
In: Computer Science
In computer science, when is the right time to find the Upper bound, Lower bound, and Tight bound? And what does Tight Bound show us?
In: Computer Science
- Part 2 – 4 Desk Checking Exercises – these are 3 programs (pseudocode) that are working and 1 program (Python). Explainthe intent of the pseudocode / program. If you use test data, note the test data. . You are NOT trying to find mistakes.
|
Use this textbox to explain the pseudocode/ code intent. Include any test data used: |
What does this do? Desk Checking #4: Explain
the intent of this code. Be as specific as
possible.
List the data you use for example data.
import random
number = random.randint(1, 10)
keepGoing = input("Do you want to guess a number? Enter Y or N ")
while (keepGoing != "Y") and (keepGoing != "N"):
keepGoing = input("Invalid Response." + " Please type Y or N. ")
while keepGoing == "Y":
stringNumber = input("I'm thinking of a number. .\n Try to guess by entering a number between 1 and 10 ")
userNumber = int(stringNumber)
while (userNumber < 1) or (userNumber > 10):
stringNumber = input("Number must be in the range of 1 to 10: Please try again: ")
userNumber = int(stringNumber)
if userNumber == number:
keepGoing = "N"
print("You are a genius. That's correct!")
else:
keepGoing = input("That's not correct. Do you want to guess again? Enter Y or N ")
while (keepGoing != "Y") and (keepGoing != "N"):
keepGoing = input("Invalid Response." + " Please type Y or N. ")
In: Computer Science
write a java prog that include an array of strings of size
50
String[] strings = new String[50];
then find the max length of the inputs inside a method
keep reading from the user until user enters keyword to stop
input :
may ala
jony ram
asd fgghff
daniel
jwana
output :
max length : 10
In: Computer Science
Questions:
Restrictions:
In: Computer Science
PLEASE ANSWER IN C
Assume that an int variable age has been declared and already given a value and assume that a char variable choice has been declared as well. Assume further that the user has just been presented with the following menu:
(Yes, this menu really IS a menu!)
Write some code that reads a single character (S or T or B) into choice. Then the code prints out a recommended accompanying drink as follows:
If the value of age is 21 or lower, the recommendation is "vegetable juice" for steak, "cranberry juice" for trout, and "soda" for the burger. Otherwise, the recommendations are "cabernet", "chardonnay", and "IPA" for steak, trout, and burger respectively. Regardless of the value of age, your code should print "invalid menu selection" if the character read into choice was not S or T or B.
In: Computer Science
(Sort ArrayList) Write the following method that sorts an ArrayList:
public static <E extends Comparable<E>>
void sort(ArrayList<E> list)
Write a program to test the method with three different arrays:
Integers: 2, 4, and 3;
Doubles: 3.4, 1.2, and -12.3;
Strings: "Bob", "Alice", "Ted", and "Carol"
In: Computer Science
What are the inputs and outputs for functional analysis and allocation? Explain how inputs are transformed to outputs. In what life cycle phase(s) is functional analysis and allocation performed?
In: Computer Science
python
Write a Loop class. The contents of a loop object are represented internally as a simple python list with the following additional instance variables:
loop - a python list containing the elements of the loop list
head - which stores the index of the first element of the loop list
current - which stores the index of the last element of the loop list
size - which stores how many actual elements are in the loop
max - which stores the max number of elements that can be in a loop
Note that current and head will be the same when the list is empty, and when the list contains a single element.
And methods:
__init__(self, max) - which constructs an empty loop object;
__str__(self) - which returns a string representing the loop object as described below;
add(element) - which adds the element to the end of the loop (i.e. at the position of current + 1)
empty() - which says whether there are any elements in the loop;
count() - which says how many elements currently are in the loop;
delete() - which returns the first item from the loop (i.e. at the position of head) and removes it from the loop;
max() - returns the max number of elements allowed in the loop.
__init__ initializes the empty locations in the loop list to None. Assume that max is always greater than the number of elements to be in the loop at any one time. When an element is being added to an empty loop, it always goes into the first location (index 0) in the loop list and head and current are reset to 0.
If an attempt is made to delete() from an empty loop then delete() returns None. When an element is deleted from the loop its value is changed to None. Remember, your code needs to properly maintain the correct values of loop, head, current and size.
__str__ formats the loop object data as follows:
<max> <size> <head> <current> <loop list>
For example, after:
x = Loop(4)
x.add(1)
x.add(3)
x.delete()
print(x)
"print(x)" prints out:
4 1 1 1 [None, 3, None, None]
For example:
| Test | Result |
|---|---|
x = Loop(5) print(x) |
5 0 0 0 [None, None, None, None, None] |
x = Loop(5) x.add(3) print(x) |
5 1 0 0 [3, None, None, None, None] |
x = Loop(3) x.add(3) x.add(2) print(x) |
3 2 0 1 [3, 2, None] |
x = Loop(3) x.add(3) x.add(2) x.delete() print(x) |
3 1 1 1 [None, 2, None] |
x = Loop(3) x.add(2) x.add(5) x.add(3) x.delete() x.add(7) print(x) |
3 3 1 0 [7, 5, 3] |
In: Computer Science
In: Computer Science
Edsger Dijkstra, an early contributor to the development of software engineering, stated that Testing can only show the presence of errors, not their........
Select one:
a. absence
b. None of the other options.
c. causes
d. presence
The following is an example of errors originated in the requirements analysis phase:
Select one:
a.
Defects in the used algorithms.
b. Misunderstanding of the client’s instructions.
c.
User interface and procedure errors.
d. Algorithmic and processing defects.
Fill out the missing word:
Software testing is a .............. process carried out by a specialized testing team.
Select one:
a. necesssary
b. random
c. formal
d. sufficient
In software testing, a software unit, several integrated software units or an entire software package are examined by ..................... the programs on a computer.
Select one:
a. writing
b. running
c. simulating
d. proving
There is no single testing technique that is guaranteed to find all defects in all programs.
Select one:
True
False
An exhaustive testing method is an effective testing strategy since it is guaranteed to find all possible defects.
Select one:
True
False
The main difference between debugging and testing is:
Select one:
a. Debugging use tools while testing does not.
b. Testing aims to locate source of the defect and to fix it while debugging aims to discover defects.
c. Debugging aims to locate the source of the defect and to fix it while testing aims to discover defects.
d. Debugging is a static V&V method while testing is a dynamic one.
A programmer forgets to add two numbers in the code. This is an example of a:
Select one:
a. A software failure.
b. A software error.
c. A software defect.
d. None of the other choices.
A tester finds out in a test case that the actual result differs from the expected result. This is an example of:
Select one:
a. A software defect.
b. A software failure.
c. None of the other choices.
d. A software error.
An example of a white-box testing technique is:
Select one:
a. Review.
b. Code coverage.
c. Equivalence class partitioning.
d. Inspection.
In: Computer Science