C language <stdio.h> (functions)
Write a program to display a table of Fahrenheit temperatures and their equivalent Celsius temperatures. Create a function to do the conversion from Fahrenheit to Celsius. Invoke the function from within a for loop in main() to display the table. Ask the user for a starting temperature and and ending temperature. Validate that the starting temperature is within the range of -100 to 300 degrees, Validate that the ending temperature is in the range of -100 to 300 degrees, and is also greater than the starting temperature. Use a decision inside the ending temperature validation loop to display either the "out-of-range" message or the "greater than starting temperature" message.
The formula for converting a Fahrenheit temperature to Celsius
is:
C = (5 / 9) * (F - 32)
Use this exact formula - do not pre-calculate 5/9 as .56 (you will
have to type cast one of the numbers to a double for the equation
to work correctly).
Format the Celsius temperatures to 1 decimal place.
Example Run #1:
(bold type is what is entered by the user)
Enter a starting Fahrenheit temperature:
-200
The starting temperature must be between -100 and 300
degrees.
Please re-enter the starting temperature: 0
Enter an ending Fahrenheit temperature: 500
The ending temperature must be between -100 and 300 degrees.
Please re-enter the ending temperature: -20
The ending temperature, -20, must be greater than the starting
temperature.
Please re-enter the ending temperature: 20
Fahrenheit Celsius
0 xx.x
1 xx.x
2 xx.x
3 xx.x
4 xx.x
5 xx.x
6 xx.x
7 xx.x
8 xx.x
9 xx.x
10 xx.x
11 xx.x
12 xx.x
13 xx.x
14 xx.x
15 xx.x
16 xx.x
17 xx.x
18 xx.x
19 xx.x
20 xx.x
The example run shows EXACTLY how your program input and output will look.
In: Computer Science
Create a command based menu using functions.
The structure should be as followed:
In: Computer Science
Please convert the following machine code (given in Hex format) into assembly code and next, b) provide the semantics of each instruction using RTL
i) 0x8FA80004
ii) 0x12110005
iii) 0x02429820
iv) ox081000A9
v) 0C0000FA
In: Computer Science
public static void main(String [] args)
{
int[] a = new int[20];
a[0] = 0;
a[1] = 1;
for(int i = 2; i < 20; i++){
a[i] = a[i - 1] + a[i - 2];
}
for(int i = 0; i < a.length; i++)
System.out.println(a[i]);
}
what would be the code when you convert this code, which is java into assembly code? Convert java into assembly code for the code above
In: Computer Science
Write a program in C++(no import of Javax or anything similar)
that does the following:
There is a class human and a derived class student.
The enum in this case is gender(male, female)
Read in a text file of unknown line number that is
formatted:
name;id;enum
name1;id1;enum1
The delimiter is ';'
Dynamically allocate student objects and store the objects in the
array humanList (an array of human pointers). Include a counter for
number of lines in the file as well.
In: Computer Science
describe how a company uses crowdsourcing to assist with its business.
In: Computer Science
If a heavily updated table contains many indexes, the time required to rebuild those indexes may degrade the overall performance of the database.
Select one:
a. True
b. False
In: Computer Science
#Write a function called clean_data. clean_data takes one
#parameter, a dictionary. The dictionary represents the
#observed rainfall in inches on a particular calendar day
#at a particular location. However, the data has some
#errors.
#
#clean_data should delete any key-value pair where the value
#has any of the following issues:
#
# - the type is not an integer or a float. Even if the value
# is a string that could be converted to an integer (e.g.
# "5") it should be deleted.
# - the value is less than 0: it's impossible to have a
# negative rainfall number, so this must be bad data.
# - the value is greater than 100: the world record for
# rainfall in a day was 71.8 inches
#
#Return the dictionary when you're done making your changes.
#
#Remember, the keyword del deletes items from lists
#and dictionaries. For example, to remove the key "key!" from
#the dictionary my_dict, you would write: del my_dict["key!"]
#Or, if the key was the variable my_key, you would write:
#del my_dict[my_key]
#
#Hint: If you try to delete items from the dictionary while
#looping through the dictionary, you'll run into problems!
#We should never change the number if items in a list or
#dictionary while looping through those items. Think about
#what you could do to keep track of which keys should be
#deleted so you can delete them after the loop is done.
#
#Hint 2: To check if a variable is an integer, use
#type(the_variable) == int. To check if a variable is a
float,
#use type(the_variable) == float.
#Write your function here!
#Below are some lines of code that will test your
function.
#You can change the value of the variable(s) to test your
#function with different inputs.
#
#If your function works correctly, this will originally
#print (although the order of the keys may vary):
#{"20190101": 5, "20190103": 7.5, "20190104": 0, "20190107":
1}
rainfall = {"20190101": 5, "20190102": "6", "20190103": 7.5,
"20190104": 0, "20190105": -7, "20190106": 102,
"20190107": 1}
print(clean_data(rainfall))
In: Computer Science
A company uses codes to represent its products, for example ABC2475A5R-14. Valid codes must have:
At least 10 characters (some codes have more than 10 characters)
Positions 4 through 7 must be digits (and represents the country in which the product will be sold)
The character in the 10th position must be a capital letter and represents the security level of the product.
Write a Python program that will read 10 product codes from a text file (Codes.txt - attached below). Determine if each conforms to the rules listed above:
If it does conform, print a heading: Valid Code(s) are: and list the codes that are valid. If it does not conform, print a heading: Invalid Code(s) are: and list the codes that area invalid. Be sure to test all possible combinations.
Further, if the code is valid, due to new government security laws, products with a security level of R (restricted) are no longer to be sold in countries with a country code of 2000 or higher. Output a heading: Invalid Restricted Code(s) are: and list the codes that are invalid in case you encounter any products that violate these new laws.
here is the text file data
XYZ2755R-14
RST1234A6A-12
UVW24a6R7R-13
PQR3999F85-11
STI1281J9A-04
FOR2561T4R-54
BID2075U3R-55
AGA1475P1B01
JBT2175E5X-04
KAM1145X2R-05
In: Computer Science
In: Computer Science
C++
•Write a program that evaluates a postfix expression (assume it’s valid) such as
6 2 + 5 * 8 4 / -
•The program should read a postfix expression consisting of digits and operators into a string.
•The algorithm is as follows:
1.While you have not reached the end of the string, read the expression from left to right.
–If the current character is a digit, Push its integer value onto the stack (the integer value of a digit character is its value in the computer’s character set minus the value of '0' in the computer’s character set).
–Otherwise, if the current character is an operator, Pop the two top elements of the stack into variables x and y.
–Calculate y operator x.
–Push the result of the calculation onto the stack.
2.When you reach the end of the string, pop the top value of the stack. This is the result of the postfix expression.
–[Example: In Step 2 above, if the operator is '/', the top of the stack is 2 and the next element in the stack is 8, then pop 2 into x, pop 8 into y, evaluate 8 / 2 and push the result, 4, back onto the stack. This note also applies to operator '–'.]
–The arithmetic operations allowed in an expression are
•+ addition
•– subtraction
•* multiplication
•/ division
•^ exponentiation
•% modulus
•[Note: We assume left-to-right associativity for all operators for the purpose of this exercise.] The stack should be maintained with stack nodes that contain an int data member and a pointer to the next stack node. You may want to provide the following functional capabilities:
a.function evaluatePostfixExpression that evaluates the postfix expression
b.function calculate that evaluates the expression (op1 operator op2)
c.function push that pushes a value onto the stack
d.function pop that pops a value off the stack
e.function isEmpty that determines if the stack is empty
f.function printStack that prints the stack
SAMPLE OUTPUT:
INPUT POSTFIX NOTATION: 23+2*
INFIX NOTATION: (2+3)*2
RESULT: 10
In: Computer Science
If you could build your own personal computer, what components would you purchase? Put together a list of the components you would use to create it, including a computer case, motherboard, CPU, hard disk, RAM, and DVD drive. How can you be sure they are all compatible with each other? How much would it cost? How does this compare to a similar computer purchased from a vendor such as Dell, HP or Apple?
Produce a Word document: outlining the components you would choose for a PC of your own design. Limit your cost to $1500. at the end write a paragraph summary explain why this would be better or worst than purchasing from Dell, HP or Apple etc.
In: Computer Science
Example of a document that misuses graphics. Discuss how the graphics are misused and what could be done to better them.
Please blot out any sensitive information and names
Subject: Business and Technical Report Writing
In: Computer Science
Modify the "spiral" method in the "DrawDemo" class so that a spiral appears in the center of the canvas. However, instead of displaying the lines as black, randomize the color of each line between Color.RED, Color.GREEN, and Color.BLUE (each line should be randomized, don't display a single color for the whole spiral).
import java.awt.Color;
import java.util.Random;
import java.awt.Dimension;
/**
* Class DrawDemo - provides some short demonstrations showing how
to use the
* Pen class to create various drawings.
*
* @author Michael Kölling and David J. Barnes
* @version 2016.02.29
*/
public class DrawDemo
{
private Canvas myCanvas;
private Random random;
/**
* Prepare the drawing demo. Create a fresh
canvas and make it visible.
*/
public DrawDemo()
{
myCanvas = new
Canvas("Drawing Demo", 500, 400);
random = new
Random();
}
/**
* Draw a square on the screen.
*/
public void drawSquare()
{
Pen pen = new Pen(320,
260, myCanvas);
pen.setColor(Color.BLUE);
square(pen);
}
/**
* Draw a polygon with the given number of
sides.
* @param n The number of sides.
*/
public void drawPolygon(int n)
{
Pen pen = new Pen(320,
260, myCanvas);
pen.setColor(Color.MAGENTA);
polygon(pen, n);
}
/**
* Draw a wheel made of many squares.
*/
public void drawWheel()
{
Pen pen = new Pen(250,
200, myCanvas);
pen.setColor(Color.RED);
for(int i=0; i<36;
i++) {
square(pen);
pen.turn(10);
}
}
/**
* Draw a spiral.
*/
public void drawSpiral()
{
Pen pen = new Pen(320,
260, myCanvas);
pen.setColor(Color.BLACK);
spiral(pen);
}
/**
* Draw a square in the pen's color at the
pen's location.
*/
private void square(Pen pen)
{
for(int i = 0; i < 4;
i++) {
pen.move(100);
pen.turn(90);
}
}
/**
* Draw a polygon with the given number of
side
* in the pen's color at the pen's
location.
* @param sides The number of sides.
*/
private void polygon(Pen pen, int sides)
{
for(int i = 0; i <
sides; i++) {
pen.move(100);
pen.turn(360 / sides);
}
}
/**
* Draw a spiral in the pen's color at the
pen's location.
*/
private void spiral(Pen pen)
{
// Start in the
middle.
pen.penUp();
Dimension size =
myCanvas.getSize();
pen.moveTo(size.width /
2, size.height / 2);
// Face downwards.
pen.turnTo(90);
pen.penDown();
}
/**
* Draw some random squiggles on the
screen, in random colors.
*/
public void colorScribble()
{
Pen pen = new Pen(250,
200, myCanvas);
for (int i=0;
i<10; i++) {
// pick a random color
int red = random.nextInt(256);
int green = random.nextInt(256);
int blue = random.nextInt(256);
pen.setColor(new Color(red, green, blue));
pen.randomSquiggle();
}
}
/**
* Clear the screen.
*/
public void clear()
{
myCanvas.erase();
}
}
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
/**
* Class Canvas - a class to allow for simple graphical
* drawing on a canvas.
*
* @author Michael Kölling (mik)
* @author Bruce Quig
*
* @version 2016.02.29
*/
public class Canvas
{
private JFrame frame;
private CanvasPane canvas;
private Graphics2D graphic;
private Color backgroundColor;
private Image canvasImage;
/**
* Create a Canvas with default height,
width and background color
* (300, 300, white).
* @param title title to appear in Canvas
Frame
*/
public Canvas(String title)
{
this(title, 300, 300,
Color.white);
}
/**
* Create a Canvas with default background
color (white).
* @param title title to appear in Canvas
Frame
* @param width the desired width for the
canvas
* @param height the desired height for the
canvas
*/
public Canvas(String title, int width, int
height)
{
this(title, width,
height, Color.white);
}
/**
* Create a Canvas.
* @param title title to appear in Canvas
Frame
* @param width the desired width for the
canvas
* @param height the desired height for the
canvas
* @param bgClour the desired background
color of the canvas
*/
public Canvas(String title, int width, int
height, Color bgColor)
{
frame = new
JFrame();
canvas = new
CanvasPane();
frame.setContentPane(canvas);
frame.setTitle(title);
canvas.setPreferredSize(new Dimension(width, height));
backgroundColor =
bgColor;
frame.pack();
setVisible(true);
}
/**
* Set the canvas visibility and brings
canvas to the front of screen
* when made visible. This method can also
be used to bring an already
* visible canvas to the front of other
windows.
* @param visible boolean value
representing the desired visibility of
* the canvas (true or false)
*/
public void setVisible(boolean visible)
{
if(graphic == null)
{
// first time: instantiate the offscreen image and fill it
with
// the background color
Dimension size = canvas.getSize();
canvasImage = canvas.createImage(size.width, size.height);
graphic = (Graphics2D)canvasImage.getGraphics();
graphic.setColor(backgroundColor);
graphic.fillRect(0, 0, size.width, size.height);
graphic.setColor(Color.black);
}
frame.setVisible(true);
}
/**
* Provide information on visibility of the
Canvas.
* @return true if canvas is visible, false
otherwise
*/
public boolean isVisible()
{
return
frame.isVisible();
}
/**
* Draw the outline of a given shape onto
the canvas.
* @param shape the shape object to be
drawn on the canvas
*/
public void draw(Shape shape)
{
graphic.draw(shape);
canvas.repaint();
}
/**
* Fill the internal dimensions of a given
shape with the current
* foreground color of the canvas.
* @param shape the shape object to be
filled
*/
public void fill(Shape shape)
{
graphic.fill(shape);
canvas.repaint();
}
/**
* Fill the internal dimensions of the
given circle with the current
* foreground color of the canvas.
* @param xPos The x-coordinate of the
circle center point
* @param yPos The y-coordinate of the
circle center point
* @param diameter The diameter of the
circle to be drawn
*/
public void fillCircle(int xPos, int yPos, int
diameter)
{
Ellipse2D.Double circle
= new Ellipse2D.Double(xPos, yPos, diameter, diameter);
fill(circle);
}
/**
* Fill the internal dimensions of the
given rectangle with the current
* foreground color of the canvas. This is
a convenience method. A similar
* effect can be achieved with the "fill"
method.
*/
public void fillRectangle(int xPos, int yPos,
int width, int height)
{
fill(new Rectangle(xPos,
yPos, width, height));
}
/**
* Erase the whole canvas.
*/
public void erase()
{
Color original =
graphic.getColor();
graphic.setColor(backgroundColor);
Dimension size =
canvas.getSize();
graphic.fill(new
Rectangle(0, 0, size.width, size.height));
graphic.setColor(original);
canvas.repaint();
}
/**
* Erase the internal dimensions of the
given circle. This is a
* convenience method. A similar effect can
be achieved with
* the "erase" method.
*/
public void eraseCircle(int xPos, int yPos, int
diameter)
{
Ellipse2D.Double circle
= new Ellipse2D.Double(xPos, yPos, diameter, diameter);
erase(circle);
}
/**
* Erase the internal dimensions of the
given rectangle. This is a
* convenience method. A similar effect can
be achieved with
* the "erase" method.
*/
public void eraseRectangle(int xPos, int yPos,
int width, int height)
{
erase(new
Rectangle(xPos, yPos, width, height));
}
/**
* Erase a given shape's interior on the
screen.
* @param shape the shape object to be
erased
*/
public void erase(Shape shape)
{
Color original =
graphic.getColor();
graphic.setColor(backgroundColor);
graphic.fill(shape);
// erase by filling background color
graphic.setColor(original);
canvas.repaint();
}
/**
* Erases a given shape's outline on the
screen.
* @param shape the shape object to be
erased
*/
public void eraseOutline(Shape shape)
{
Color original =
graphic.getColor();
graphic.setColor(backgroundColor);
graphic.draw(shape); //
erase by drawing background color
graphic.setColor(original);
canvas.repaint();
}
/**
* Draws an image onto the canvas.
* @param image the Image
object to be displayed
* @param
x x co-ordinate for Image
placement
* @param
y y co-ordinate for Image
placement
* @return returns boolean value
representing whether the image was
* completely
loaded
*/
public boolean drawImage(Image image, int x, int
y)
{
boolean result =
graphic.drawImage(image, x, y, null);
canvas.repaint();
return result;
}
/**
* Draws a String on the Canvas.
* @param text the String to be
displayed
* @param x x
co-ordinate for text placement
* @param y y
co-ordinate for text placement
*/
public void drawString(String text, int x, int
y)
{
graphic.drawString(text,
x, y);
canvas.repaint();
}
/**
* Erases a String on the Canvas.
* @param text the
String to be displayed
* @param
x x co-ordinate for text
placement
* @param
y y co-ordinate for text
placement
*/
public void eraseString(String text, int x, int
y)
{
Color original =
graphic.getColor();
graphic.setColor(backgroundColor);
graphic.drawString(text,
x, y);
graphic.setColor(original);
canvas.repaint();
}
/**
* Draws a line on the Canvas.
* @param x1 x co-ordinate of
start of line
* @param y1 y co-ordinate of
start of line
* @param x2 x co-ordinate of
end of line
* @param y2 y co-ordinate of
end of line
*/
public void drawLine(int x1, int y1, int x2, int
y2)
{
graphic.drawLine(x1, y1,
x2, y2);
canvas.repaint();
}
/**
* Sets the foreground color of the
Canvas.
* @param newColor the new
color for the foreground of the Canvas
*/
public void setForegroundColor(Color
newColor)
{
graphic.setColor(newColor);
}
/**
* Returns the current color of the
foreground.
* @return the color of the
foreground of the Canvas
*/
public Color getForegroundColor()
{
return
graphic.getColor();
}
/**
* Sets the background color of the
Canvas.
* @param newColor the new
color for the background of the Canvas
*/
public void setBackgroundColor(Color
newColor)
{
backgroundColor =
newColor;
graphic.setBackground(newColor);
}
/**
* Returns the current color of the
background
* @return the color of the
background of the Canvas
*/
public Color getBackgroundColor()
{
return
backgroundColor;
}
/**
* changes the current Font used on the
Canvas
* @param newFont new font to
be used for String output
*/
public void setFont(Font newFont)
{
graphic.setFont(newFont);
}
/**
* Returns the current font of the
canvas.
* @return the font
currently in use
**/
public Font getFont()
{
return
graphic.getFont();
}
/**
* Sets the size of the canvas.
* @param width new
width
* @param height new
height
*/
public void setSize(int width, int height)
{
canvas.setPreferredSize(new Dimension(width, height));
Image oldImage =
canvasImage;
canvasImage =
canvas.createImage(width, height);
graphic =
(Graphics2D)canvasImage.getGraphics();
graphic.setColor(backgroundColor);
graphic.fillRect(0, 0,
width, height);
graphic.drawImage(oldImage, 0, 0, null);
frame.pack();
}
/**
* Returns the size of the canvas.
* @return The
current dimension of the canvas
*/
public Dimension getSize()
{
return
canvas.getSize();
}
/**
* Waits for a specified number of
milliseconds before finishing.
* This provides an easy way to specify a
small delay which can be
* used when producing animations.
* @param milliseconds the number
*/
public void wait(int milliseconds)
{
try
{
Thread.sleep(milliseconds);
}
catch
(InterruptedException e)
{
// ignoring exception at the moment
}
}
/************************************************************************
* Inner class CanvasPane - the actual
canvas component contained in the
* Canvas frame. This is essentially a
JPanel with added capability to
* refresh the image drawn on it.
*/
private class CanvasPane extends JPanel
{
public void
paint(Graphics g)
{
g.drawImage(canvasImage, 0, 0, null);
}
}
}
import java.awt.Color;
import java.util.Random;
/**
* A pen can be used to draw on a canvas. The pen maintains a
position, direction, color,
* and an up/down state. The pen can be moved across the canvas. If
the pen is down, it
* leaves a line on the canvas when moved. (If it is up, it will not
draw a line.)
*
* @author Michael Kölling & David J. Barnes
* @version 2016.02.29
*/
public class Pen
{
// constants for randomSquiggle method
private static final int SQIGGLE_SIZE =
40;
private static final int SQIGGLE_COUNT =
30;
private int xPosition;
private int yPosition;
private int rotation;
private Color color;
private boolean penDown;
private Canvas canvas;
private Random random;
/**
* Create a new Pen with its own canvas.
The pen will create a new canvas for
* itself to draw on, and start in the
default state (centre of canvas, direction
* right, color black, pen down).
*/
public Pen()
{
this (280, 220, new
Canvas("My Canvas", 560, 440));
}
/**
* Create a new Pen for a given canvas. The
direction is initially 0 (to the right),
* the color is black, and the pen is
down.
*
* @param xPos the initial horizontal
coordinate of the pen
* @param yPos the initial vertical
coordinate of the pen
* @param drawingCanvas the canvas to draw
on
*/
public Pen(int xPos, int yPos, Canvas
drawingCanvas)
{
xPosition = xPos;
yPosition = yPos;
rotation = 0;
penDown = true;
color =
Color.BLACK;
canvas =
drawingCanvas;
random = new
Random();
}
/**
* Move the specified distance in the
current direction. If the pen is down,
* leave a line on the canvas.
*
* @param distance The distance to move
forward from the current location.
*/
public void move(int distance)
{
double angle =
Math.toRadians(rotation);
int newX = (int)
Math.round(xPosition + Math.cos(angle) * distance);
int newY = (int)
Math.round(yPosition + Math.sin(angle) * distance);
moveTo(newX,
newY);
}
/**
* Move to the specified location. If the
pen is down, leave a line on the canvas.
*
* @param x The x-coordinate to
move to.
* @param y The y-coordinate to
move to.
*/
public void moveTo(int x, int y)
{
if (penDown) {
canvas.setForegroundColor(color);
canvas.drawLine(xPosition, yPosition, x, y);
}
xPosition = x;
yPosition = y;
}
/**
* Turn the specified amount (out of a 360
degree circle) clockwise from the current
* rotation.
*
* @param degrees The amount of degrees to
turn. (360 is a full circle.)
*/
public void turn(int degrees)
{
rotation = rotation +
degrees;
}
/**
* Turn to the specified direction. 0 is
right, 90 is down, 180 is left, 270 is up.
*
* @param angle The angle to turn to.
*/
public void turnTo(int angle)
{
rotation = angle;
}
/**
* Set the drawing color.
*
* @param newColor The color to use for
subsequent drawing operations.
*/
public void setColor(Color newColor)
{
color = newColor;
}
/**
* Lift the pen up. Moving afterwards will
not leave a line on the canvas.
*/
public void penUp()
{
penDown = false;
}
/**
* Put the pen down. Moving afterwards will
leave a line on the canvas.
*/
public void penDown()
{
penDown = true;
}
/**
* Scribble on the canvas in the current
color. The size and complexity of the
* squiggle produced is defined by the
constants SQIGGLE_SIZE and SQIGGLE_COUNT.
*/
public void randomSquiggle()
{
for (int i=0;
i<SQIGGLE_COUNT; i++) {
move(random.nextInt(SQIGGLE_SIZE));
turn(160 + random.nextInt(40));
}
}
}
In: Computer Science
Wilson Car Repair must record information about customer’s vehicles that are coming in for repair. A program is needed to record the customer name, phone number, Type of work done, type of car, the number of labor hours, and the total amount for the parts, and a grand total amount for the repair of the vehicle. A 10% discount will be given if paid in cash. If the customer is a member of the “Wilson Car Repair Savings Club,” they get a 20% discount. You can adjust this project in any way you want. Just make sure you are doing some calculations.
You can adjust this project in any way you want.
You can make it easier or more challenging. Just make sure you are doing some calculations.
Be sure to submit an IPO along with your input screen and your output screen. You can draw screens or use Visio to make them.
In: Computer Science