C++
function to a string into enum
function to a enum into a string
check valid / loop ( asking a couple of times until answer invaild)
For example
Enum Fruit ( APPLE, STRAWBERRY, BLUEBERRY, BLACKBERRY)
output should be
what is your favorit fruit? : strawberry
you will have STRAWBERRY.
what is your favorite fruite : peach
invaild
TIA
In: Computer Science
Assignment Description
Write a program that will have a user guess whether a person is a musician or a writer. You will create a
group of four names, two musicians and two writers, and show the user a name randomly selected from
the four. The user will then guess whether they think the name belongs to a musician or writer. After a
guess, the program will tell the user whether they are correct, repeat the name, and reveal the correct
answer.
Tasks
1) The program needs to contain the following
a.
A comment header containing your name and a brief description of the program
b. At least 5 comments besides the comment header explaining what your code does
c.
Four string variables, two musicians and two writers
d. A way to randomly display one of the four names to the user
e. Output asking the user whether the name displayed is a musician or a writer
i. If the user guesses correctly, congratulate them before outputting the displayed
name and the correct answer
ii. If the user guesses incorrectly, output the displayed name and the correct
answer
f.
“Press enter to continue” and Console.Read(); at the end of your code
2) Upload the completed .cs file onto the Assignment 3 submission folder. To access the .cs file:
a.
Right click on your program tab
b. Click “Open containing folder”
c.
The file you are working on will be there with a .cs extention, upload the .cs file
In: Computer Science
In this assignment, you will implement Breadth First Search (BFS). The input to your program is a graph in the adjacency list format. The input graph has at most 100 vertices. Your program must initiate a BFS from vertex 2 of the graph. If the graph is connected, your program must output “Graph is connected”. If the graph is disconnected, your program must output “Graph is not connected”. Your program should read from an input file: data2.txt and write to the output file: out2.txt.
Your program should be written in C or C++. You can use STL for a queue but not for a graph.
Input Example
1 3 4
2 4
3 1 4
4 2 1 3
1 2 4
2 1 3
3 2 4
4 1 3
1 2
2 1
3 4
4 3
In: Computer Science
need to write code for a Paint job estimator program on python
specs:
A painting company has determined that for every 350 square feet of wall space, one gallon of paint and six hours of labor are required. The company charges $62.25 per hour for labor. Write a program call paintjobestimator.py that asks the user to enter the square feet of wall space to be painted and the price of the paint per gallon. The program is to display the following information.
At the end of one estimate the user it to be asked if they would like to perform another estimate. Use the prompt: Would you like to do another estimate? (y/n) If the user answers y, then the program is to accept input for another estimate. If the user answers with anything other than y, the program is to exit.
The user input should not be able to crash the program. If the user provides invalid input the program should tell the user why the input is invalid and ask again for the input.
The square feet of wall space and the price of the paint per gallon must be positive values. If the user enters 0 or a negative value, the program should tell the user why the input is invalid and ask again for the input.
The output is to be nicely formatted. Hours of labor is to be displayed to one decimal point (example: 12.4 hours). Gallons of paint is to be displayed as an integer value with nothing shown to the right of the decimal point (example: 5). Total labor charges is to be displayed to two decimal points and a $ is to be displayed at the start of the total labor charge value (example: $152.64).
The gallons of paint is rounded up to whole gallons because the paint is colored and mixed in whole gallons. If paint is left over it can’t be used on another job. You will need to find a way in Python to do the math to calculate the gallons of paint so that the result is a whole number that is a rounded up value based on the division of the square feet of space by the 350 square feet per gallon. For example, if the area to be painted is 1800 square feet, then 1800 / 350 is 5.142857 gallons. The rounded up whole gallons result is 6. Five gallons of paint is not enough. The need for some amount more than 5 gallons means the job requires 6 gallons even if all of it will not be used.
this is what i have so far:
import math
def main():
while True:
# Taking the input from the user for the square feet of the wall to paint and ask use until the user enters positive integer value
while True:
square_feet = input('Enter square feet of wall to paint: ')
square_feet = int(square_feet)
if square_feet < 0:
print('square feet has to be positive integer')
continue
elif square_feet == 0:
print('square feet must be positive not zero')
continue
# if square feet is greater than 0 the loop terminates
else:
break
# Taking the input from the user for the pricePaint of the painting bucket and ask the user until the user enters positive integer value
while True:
pricePaint = input('Enter pricePaint of paint per gallon: ')
pricePaint = int(pricePaint)
if pricePaint < 0:
print('price has to be positive integer')
continue
elif pricePaint == 0:
print('price has to be positive integer not zero')
continue
# if pricePaint > 0 the loop terminates
else:
break
# getting Gallons based on the price of the paint
Gallons = square_feet / 350
# calculating the number of numOfHours required to paint
number_of_hours = Gallons * 6
Gallons = math.ceil(Gallons)
# getting cost of the paint from Gallons
paintCost = pricePaint * Gallons
# getting theLaborCharge based on number of numOfHours
the_Labor_Charge = 62.25 * number_of_hours
# calculating total paint cost
totalCost = paintCost + the_Labor_Charge
print("Gallons: %5d, number of hours of labor: %.1f, Paint Cost:
%.2f, the Labor Charge: $%.2f, Total Paint Cost: $%.2f" % (
Gallons, number_of_hours, paintCost, the_Labor_Charge,
totalCost))
# getting choice from user
choice = input('Would you like to do another estimate(y/n)? ')
# if the choice is yes the program will do another estimate
if choice.upper() == 'Y':
pass
# if the choice is no or anything then program will terminate
elif choice.upper() == 'N' or choice.upper() != 'N':
break
if __name__ == "__main__":
main()
----
when the user puts in a negative number or 0 for the square ft of wall space and price of paint it advises them to use another value but when they use a decimal number such as "9.99" it crashes.
I need to make to where it takes all kinds of inputs including decimal numbers and advise them to try another value if they put in 0 or a negative number. if someone could also help me tidy up how it spits the end result it would be great
In: Computer Science
ASSEMBLY LANGUAGE PROGRAMMING
Q:Write a complete assembly program that inputs a small signed integer n, whose value can fit within 8 bits, and outputs the value of the expression n2 – n + 6.
In: Computer Science
Write the c++ program of Secant Method and Fixed point Method in a one program using switch condition .Like :
cout<<"1.Secant Method \n 2. Fixed point Method\n"<<endl; if press 1 then work Secant Method if press 2 then work Fixed point Method .so please writhe the code in c++ using switch case.and the equation given down consider the equation in the given.Note: Must showt the all the step of output all the iteration step shown in the program .in program must shown all the step of iteration result
for secant method equation :4x3-2x-6=0
for fixed point=x2-x-1=0
Please in every itaration must be shown the output then finally Got the root
In: Computer Science
Write a program that checks whether or not a date entered in by the user is valid. Display the date and say if it is valid. If it is not valid explain why.
I don't need the coding. Just help with the questions 1 and 2.
In: Computer Science
Using the idea of the Bubble Sort algorithm, design an algorithm in pseudocode that gets 3 numbers a, b, c, from the user, and prints the 3 numbers in ascending order
In: Computer Science
In each of the projects that follow, you should write a program that contains an introductory docstring. This documentation should describe what the program will do (analysis) and how it will do it (design the program in the form of a pseudocode algorithm). Include suitable prompts for all inputs, and label all outputs appropri- ately. After you have coded a program, be sure to test it with a reasonable set of legitimate inputs.
5 An object’s momentum is its mass multiplied by its velocity. Write a pro- gram that accepts an object’s mass (in kilograms) and velocity (in meters per second) as inputs and then outputs its momentum.
6 The kinetic energy of a moving object is given by the formula KE=(1/2)mv2, where m is the object’s mass and v is its velocity. Modify the program you created in Project 5 so that it prints the object’s kinetic energy as well as its momentum.
Write a program that takes as input a number of kilometers and prints the corresponding number of nautical miles. Use the following approximations:
- A kilometer represents 1/10,000 of the distance between the North Pole and the equator.
- There are 90 degrees, containing 60 minutes of arc each, between the North Pole and the equator.
- A nautical mile is 1 minute of an arc.
*please use IDLE( python 3.7)
In: Computer Science
Please convert decimal value -32760 into 2's complement binary value
In: Computer Science
Part 2: Insertion Sort
Q3. Arrange the following arrays in ascending order using Insertion sort. Show all steps.
7 11 2 9 5 14
Q4. State the number of comparisons for each pass.
Pass |
# comparisons |
1st |
|
2nd |
|
3rd |
|
4th |
|
5th |
In: Computer Science
convert 0x41BA8000 to IEEE-754 floating-point value
In: Computer Science
Using Java:
Implement print2D(A) so that it prints out its 2D array argument A in the matrix form.
Implement add2Ds(A,B) so that it creates and returns a new 2D array C such that C=A+B.
Implement multiScalar2D(c,A) so that it creates and returns a new 2D array B such that
B=c×A.
Implement transpose2D(A), which creates and returns a new 2D array B such that B is
the transpose of A.
Your output should look like the following:A=
1234 5678 9 10 11 12
B=
2468 10 12 14 16 18 20 22 24
A+B=
3 6 9 12 15 18 21 24 27 30 33 36
5XA=
51015 20 25 30 35 40 45 50 55 60
Transpose of A =
159 2 6 10 3 7 11 4 8 12
Note that your methods should work for 2D arrays of any sizes.
In: Computer Science
convert 0x41BA8000 to IEEE-754 floating-point value
In: Computer Science
Complete the code that inserts elements into a list. The list should always be in an ordered state.
#include <stdio.h>
#include <stdlib.h>
/* list of nodes, each with a single integer */
struct element {
struct element *next;
int value;
};
/* protypes for functions defined after main */
struct element *elementalloc(void);
struct element *listinitialize();
struct element *insertelement(struct element *, int);
void printlist(struct element *);
/* main
* Creates an ordered list
* Elements added to the list must be inserted maintaining the
list
* in an ordered state
*/
int main() {
struct element *listhead = NULL;
listhead = listinitialize();
for (int i = 3; i < 100; i+=11){
listhead = insertnewelement(listhead, i);
}
printlist(listhead);
}
/* allocate memory for a new list element */
struct element *elementalloc(void) {
return (struct element *)malloc(sizeof(struct element));
}
/* simple list initialization function */
struct element *listinitialize() {
const int numbers[7] = {4, 9, 13, 18, 27, 49, 60};
struct element *newlist = NULL;
struct element *tail = NULL;
struct element *temp = NULL;
for (int i = 0; i < 7; i++) {
if (newlist == NULL) {
newlist = elementalloc();
newlist->next = NULL;
newlist->value = numbers[i];
tail = newlist;
} else {
temp = elementalloc();
temp->value = numbers[i];
temp->next = NULL;
tail->next = temp;
tail = tail->next;
}
}
return newlist;
}
/* function to insert elements into an ordered list */
struct element *insertnewelement(struct element *listhead, int x)
{
struct element *newelement;
newelement = elementalloc();
struct element *iter = listhead;
while( ) {
}
return listhead;
}
/* print the list and the respective memory locations in list
order */
void printlist(struct element *listhead)
{
while (listhead != NULL) {
printf("Memory: %p contains value: %d\n", listhead,
listhead->value);
listhead = listhead->next;
}
}
In: Computer Science