If none of the above conditions are met, simply print a blank new line
In: Computer Science
•Formal definition as a search problem (tic tac toe):
–Initial state: ??
–Player(s): ??
–Actions(s): ??
–Result(s,a): ??
–(2nd ed.: Successor function: ??
–Terminal-Test(s): ??
–Utility function(s,p): ??
•E.g., win (+1), lose (-1), and draw (0) in tic-tac-toe.
In: Computer Science
/*You will be have to round numbers very often so you decided to
create your own function round_off()
that will receive the number to be rounded and the number of
decimal digits that the number should be rounded to and will
return
the value rounded to the specified number of decimal digits. You
need to create a program to test the function.
It will ask the user to enter the double precision real number to
be rounded and a whole number indicating the number of decimal
digits.
It will then display the original number with ten digits and the
rounded value (also a double precision real number) with the number
of
digits specified by the user plus 2 more.
This assignment will be completed in two steps:
1) First you will implement the algorithm shown below in which the
rounding will be done in main()
2) Once you have this working you will need to modify your solution
so you: Declare the prototype of the function above main()
Call the function in main() to do the rounding Define the function
below main()
*/
#include <iostream>
// to use cin and cout
#include <typeinfo>
// to be able to use operator
typeid
// Include here the libraries that your program needs to compile
using namespace std;
// Ignore this; it's a little function used for making
tests
inline void _test(const char* expression, const char* file, int
line)
{
cerr << "test(" << expression << ")
failed in file " << file;
cerr << ", line " << line << "."
<< endl << endl;
}
// This goes along with the above function...don't worry about
it
#define test(EXPRESSION) ((EXPRESSION) ? (void)0 :
_test(#EXPRESSION, __FILE__, __LINE__))
// Insert here the prototype of the function here
int main()
{
// Declare variable value, valuero that hold double precision real
numbers
double value;
double valuero;
// Declare variable decdig that holds whole numbers
int decdig;
// Prompt the user to "Enter the real number: "
cout << "Enter the real number: ";
// Read from keyboard the value entered by the user and assign it
to side
cin >> value;
// Prompt the user to "Enter number of digits: "
cout << "Enter number of digits: ";
// Read from keyboard the value entered by the user and assign it
to decdig
cin >> decdig;
// Round the real number to the number of decimal digits specified
and assign the result to valuero
// Format the output to display the numbers in fixed format with ten decimal digits
// Display on the screen, using 23 columns, the message
// "The original number is ", value
// Format the output to display the numbers in fixed format with the number of decimal digits specified plus 2
// Display on the screen, using 23 columns, the message
// "The rounded number is ", valuero
system("pause");
// Do NOT remove or modify the following statements
cout << endl << "Testing your solution"
<< endl << endl;
test(typeid(value) == typeid(1.));
//
Incorrect data type used for value
test(typeid(valuero) == typeid(1.));
// Incorrect data type used
for valuero
test(typeid(decdig) == typeid(1));
//
Incorrect data type used for decdig
/*
test(fabs(round_off(125.123456789,2) - 125.12 ) <
0.001);
// Incorrect rounding to two decimal
digits
test(fabs(round_off(125.123456789,4) - 125.1235) <
0.00001); //
Incorrect rounding to four decimal digits
test(fabs(round_off(125.987654321,0) - 126.) <
0.001);
// Incorrect rounding to no
decimal digits
test(fabs(round_off(125.987654321, 5) - 125.98765)
< 0.000001);
// Incorrect rounding to five decimal digits
*/
system("pause");
return 0;
}
//************************ Function definition
*************************
// Read the handout carefully for detailed description of the
functions that you have to implement
// Rounds the value received in the first parameter to the
number of digits received in the second parameter
In: Computer Science
Write a MIPS Assembly Language program to perform the following operations:
int RecurseFunc( int Dn, int Up )
{
if( Dn < 1 ) return 0;
return Dn * Up + RecurseFunc( Dn - 1, Up + 1 );
}
In: Computer Science
Java
Write a method, makeUserName, that is passed two Strings and an int: the first is a first name, the second is a last name, and the last is a random number. The method returns a user name that contains the last character of the first name, the first five characters of the last name (assume there are five or more characters in last name), and the random number. An example: Assume that “John”, “Smith”, 45, are passed when the method is called, it will return “nSmith45” as the user name.
In: Computer Science
write a c code to test the 3rd and 8th bit set or not
(1 or 0).
if both set, display "true";
if either one set, display "half true";
if neither set, display "false".
In: Computer Science
Write a program using integers usernum and x as input, and output usernum divided by x four times. You should prompt the user with the words: Enter the first integer: at which time the users enters a number, and then Enter the second integer: at which time the user enters the second number. The prompts must be EXACTLY as written, including the colon (:) character, or your test cases will fail. Since you are prompting the user for input, you should not enter anything into the (optional) input box below, but input your numbers after your prompts.
Ex: If the input is:
Enter the first integer: 2000 Enter the second integer: 2
Then the output is:
1000 500 250 125
Note: In Python 3, integer division discards fractions. Ex: 6 // 4 is 1 (the 0.5 is discarded).
In: Computer Science
This problem requires you to prompt the user for some information, and apply simple arithmetic operation to generate an output.
We all know that driving is expensive. So let's write a program to observe this.
You should prompt the user with the words: Enter miles per gallon: at which time the users enters a number, and then Enter the gas price:at which time the user enters the second number. The prompts must be EXACTLY as written, including the colon (:) character, or your test cases will fail. Since you are prompting the user for input, you should not enter anything into the (optional) input box below, but input your numbers after your prompts.
Both inputs should be read as float data type , and your program will output the gas cost for 10 miles, 50 miles, and 400 miles. Due to the way floating point numbers are internally stored, there can be some discrepancies with the precision of calculations depending on the order things are done. To prevent this from causing your submission to be marked incorrect, please calculate the cost in the following order: The miles increment (10, 50, or 400) multiplied by 1.0/miles per gallon multiplied by the gas price.
Example: If the input is:
Enter miles per gallon:20.0 Enter the gas price:3.1599
Then the output is:
1.57995 7.89975 63.198
Note: Real per-mile cost would also include maintenance and depreciation.
Someone please help! Can't get it right! (This is python)
In: Computer Science
In this homework, we will write the code that will take an expression (input) from the user in infix notation and convert that to corresponding postfix notation and evaluate its value.
Task 0: Use the starter code to start. All the needed functions and their functionalities are given in the starter code.
Task 1: Complete the startercodeinfixtopostfix.c file
Task 2: Complete the startercodeevaluatepostfix.c file
Sample Input/Output:
(Infix to postfix)
Input: (A + B)*C-D*E
Output: A B + C * D E * -
Input: ( ( A + B ) * D ) ↑ ( E - F)
Output: A B + D * E F-^
Input: ((A – (B + C)) * D) ↑ (E + F)
Output: A B C + - D * E F + ↑
Input: a + b * c + (d * e + f) * g
Output: a b c * + d e * f + g * +
Input: (4+8)*(6-5)/((3-2)*(2+2))
Output: 4 8 + 6 5 - * 3 2 – 2 2 + * /
Input: 3+4*5/6
Output: 3 4 5 * 6 /+
Input: 3 + (4 * 5 – (6 / 7 ↑ 1 ) * 9 ) * 1
Output: 345*671^/9*-1*+
(Evaluate postfix expression)
Input: 4 8 + 6 5 - * 3 2 – 2 2 + * /
Evaluation result: 3
Input: 3 4 5 * 6 /+
Evaluation result: 6
Input: 345*671^/9*-1*+
Evaluation result: 23
StarterCodeEvaluatePostfix.c:
#define SIZE 50 /* Size of Stack */ #include <ctype.h> #include <string.h> #include <stdlib.h> #include <stdio.h> #include <math.h> int stack[SIZE]; int top=-1; /* Global declarations */ /* Function for PUSH operation */ void push(int item) { } /* Function for POP operation */ int pop() { } /* Function for precedence */ int pr(char elem) { } //Evaluate postfix expression void evaluatepostfix (char pofx[]) { } /* main function begins */ int main() { char postfix[SIZE]; printf("ASSUMPTION: The postfix expression contains single letter variables and single digit constants only.\n"); printf("\nEnter postfix expression : "); scanf("%s",postfix); evaluatepostfix(postfix); return 0; }
StarterCodeInfixToPostfix.c
#define SIZE 50 /* Size of Stack */ #include <ctype.h> #include <string.h> #include <stdlib.h> #include <stdio.h> char stack[SIZE]; int top=-1; /* Global declarations */ /* Function for PUSH operation */ void push(char item) { } /* Function for POP operation */ char pop() { } /* Function for precedence */ int pr(char elem) { } /* Function for infix to postfix conversion */ void InfixToPostfix(char infx[], char pofx[]) { } /* main function begins */ int main() { char infix[SIZE], postfix[SIZE]; /* declare infix string and postfix string */ printf("ASSUMPTION: The infix expression contains single letter variables and single digit constants only.\n"); printf("\nEnter Infix expression : "); scanf("%s",infix); InfixToPostfix(infix,postfix); /* call to convert */ printf("\n\nGiven Infix Expn: %s Postfix Expn: %s\n",infix,postfix); return 0; }
In: Computer Science
3.) Analyze the Java Program LinkRotator
_______________________________________________________________
Below is the "LinkRotator" java program:
1: package com.java24hours;
2:
3: import java.awt.*;
4: import java.awt.event.*;
5: import java.io.*;
6: import javax.swing.*;
7: import java.net.*;
8:
9: public class LinkRotator extends JFrame
10: implements Runnable, ActionListener {
11:
12: String[] pageTitle = new String[6];
13: URI[] pageLink = new URI[6];
14: int current = 0;
15: Thread runner;
16: JLabel siteLabel = new JLabel();
17:
18: public LinkRotator() {
19: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
20: setSize(300, 100);
21: FlowLayout flo = new FlowLayout();
22: setLayout(flo);
23: add(siteLabel);
24: pageTitle = new String[] {
25: "Oracle's Java site",
26: "Server Side",
27: "JavaWorld",
28: "Java in 24 Hours",
29: "Sams Publishing",
30: "Workbench"
31: };
32: pageLink[0] =
getURI("http://www.oracle.com/technetwork/java");
33: pageLink[1] = getURI("http://www.theserverside.com");
34: pageLink[2] = getURI("http://www.javaworld.com");
35: pageLink[3] = getURI("http://www.java24hours.com");
36: pageLink[4] = getURI("http://www.samspublishing.com");
37: pageLink[5] = getURI("http://workbench.cadenhead.org");
38: Button visitButton = new Button("Visit Site");
39: visitButton.addActionListener(this);
40: add(visitButton);
41: setVisible(true);
42: start();
43: }
44:
45: private URI getURI(String urlText) {
46: URI pageURI = null;
47: try {
48: pageURI = new URI(urlText);
49: } catch (URISyntaxException ex) {
50: // do nothing
51: }
52: return pageURI;
54:
55: public void start() {
56: if (runner == null) {
57: runner = new Thread(this);
58: runner.start();
59: }
60: }
61:
62: public void run() {
63: Thread thisThread = Thread.currentThread();
64: while (runner == thisThread) {
65: current++;
66: if (current > 5) {
67: current = 0;
68: }
69: siteLabel.setText(pageTitle[current]);
70: repaint();
71: try {
72: Thread.sleep(2000);
73: } catch (InterruptedException exc) {
74: // do nothing
75: }
76: }
77: }
78:
79: public void actionPerformed(ActionEvent event) {
80: Desktop desktop = Desktop.getDesktop();
81: if (pageLink[current] != null) {
82: try {
83: desktop.browse(pageLink[current]);
84: runner = null;
85: System.exit(0);
86: } catch (IOException exc) {
87: // do nothing
88: }
89: }
90: }
91:
92: public static void main(String[] arguments) {
93: new LinkRotator();
94: }
95: }
In: Computer Science
I need assistance on this problem in Pseudocode and in C++ Program
Program 3: Give a baby $5,000! Did you know that, over the last century, the stock market has returned an average of 10%? You may not care, but you’d better pay attention to this one. If you were to give a newborn baby $5000, put that money in the stock market and NOT add any additional money per year, that money would grow to over $2.9 million by the time that baby is ready for retirement (67 years)! Don’t believe us? Check out the compound interest calculator from MoneyChimp and plug in the numbers!
To keep things simple, we’ll calculate interest in a simple way. You take the original amount (called the principle) and add back in a percentage rate of growth (called the interest rate) at the end of the year. For example, if we had $1,000 as our principle and had a 10% rate of growth, the next year we would have $1,100. The year after that, we would have $1,210 (or $1,100 plus 10% of $1,100). However, we usually add in additional money each year which, for simplicity, is included before calculating the interest.
Your task is to design (pseudocode) and implement (source) for a program that 1) reads in the principle, additional annual money, years to grow, and interest rate from the user, and 2) print out how much money they have each year. Task 3: think about when you earn the most money!
Lesson learned: whether it’s your code or your money, save early and save often…
Sample run 1:
Enter the principle: 2000
Enter the annual addition: 300
Enter the number of years to grow: 10
Enter the interest rate as a percentage: 10
Year 0: $2000
Year 1: $2530
Year 2: $3113
Year 3: $3754.3
Year 4: $4459.73
Year 5: $5235.7
Year 6: $6089.27
Year 7: $7028.2
Year 8: $8061.02
Year 9: $9197.12
Year 10: $10446.8
Sample run 2 (yeah, that’s $9.4MM):
Enter the principle: 5000
Enter the annual addition: 1000
Enter the number of years to grow: 67
Enter the interest rate as a percentage: 10
Year 0: $5000
Year 1: $6600
Year 2: $8360
Year 3: $10296
Year 4: $12425.6
Year 5: $14768.2 . .
Year 59: $4.41782e+06
Year 60: $4.86071e+06
Year 61: $5.34788e+06
Year 62: $5.88376e+06
Year 63: $6.47324e+06
Year 64: $7.12167e+06
Year 65: $7.83493e+06
Year 66: $8.61952e+06
Year 67: $9.48258e+06
This assignment is about Repetition Structures.
For Pseudocode, here are key words to use
: · DO … WHILE – A loop that will always run at least once ·
FOR … ENDFOR – A loop that runs until certain criteria is met ·
WHILE … ENDWHILE – A loop that runs only while certain criteria is met ·
FOREACH … ENDFOREACH – A loop that runs over elements in a data structure · BREAK - "break out" of the current loop (or other structure) you're in and start immediately after the loop · CONTINUE - skip over the current iteration of the loop and move on to the next one
In: Computer Science
Hello, I need some assistance on completing this program in Pseudocode and in C++
Program 2: Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode) and implement (source) for a program that reads in 1) the hero’s Hit Points (HP – or health), 2) the maximum damage the hero does per attack, 3) the monster’s HP and 4) the maximum monster’s damage per attack. When the player attacks, it will pick a random number between 0 and up to the maximum damage the player does, and then subtract that from the monster. The same thing happens when the monster attacks the hero, but damage is to the hero. The program should display rounds and the HP of the hero and monster each round. If the hero or monster dies, it should print that this happened and should NOT continue (i.e. no extra text). To learn how to create random numbers, see the appendix.
Sample run 1: Enter the hero's starting hit points: 50
Enter the damage the hero’s weapon does per strike: 20
Enter the monster's starting hit points: 40
Enter the monster's damage per strike: 15
====== ROUND 1 ======
Hero attacks for: 10
Monster has 30 HP left
Monster attacks you for: 1
You have 49 HP left
====== ROUND 2 ======
Hero attacks for: 18
Monster has 12 HP left
Monster attacks you for: 7
You have 42 HP left
====== ROUND 3 ======
Hero attacks for: 0
Monster has 12 HP left
Monster attacks you for: 14
You have 28 HP left
====== ROUND 4 ======
Hero attacks for: 18
Monster has -6 HP left
The monster dies and you earn 5 XP Battle ends...
Sample run 2:
Enter the hero's starting hit points: 50
Enter the damage the hero’s weapon does per strike: 10
Enter the monster's starting hit points: 40
Enter the monster's damage per strike: 20
====== ROUND 1 ======
Hero attacks for: 1
Monster has 39 HP left
Monster attacks you for: 6
You have 44 HP left
====== ROUND 2 ======
Hero attacks for: 5
Monster has 34 HP left
Monster attacks you for: 1
You have 43 HP left
====== ROUND 3 ======
Hero attacks for: 8
Monster has 26 HP left
Monster attacks you for: 8
You have 35 HP left
====== ROUND 4 ======
Hero attacks for: 4
Monster has 22 HP left
Monster attacks you for: 5
You have 30 HP left
====== ROUND 5 ======
Hero attacks for: 7
Monster has 15 HP left
Monster attacks you for: 1
You have 29 HP left
====== ROUND 6 ======
Hero attacks for: 7
Monster has 8 HP left
Monster attacks you for: 9
You have 20 HP left
====== ROUND 7 ======
Hero attacks for: 0
Monster has 8 HP left
Monster attacks you for: 14
You have 6 HP left
====== ROUND 8 ======
Hero attacks for: 4
Monster has 4 HP left
Monster attacks you for: 11
You have -5 HP left
You are killed by the monster and lose 10 gold.
Battle ends...
his assignment is about Repetition Structures.
For Pseudocode, here are key words to use
: · DO … WHILE – A loop that will always run at least once ·
FOR … ENDFOR – A loop that runs until certain criteria is met ·
WHILE … ENDWHILE – A loop that runs only while certain criteria is met ·
FOREACH … ENDFOREACH – A loop that runs over elements in a data structure · BREAK - "break out" of the current loop (or other structure) you're in and start immediately after the loop
CONTINUE - skip over the current iteration of the loop and move on to the next one
In: Computer Science
Using MATLAB (a) Write a computer program capable of zooming and shrinking an image by pixel replication. Assume that the desired zoom/shrink factors are integers.
In: Computer Science
Write a program that can check whether or not some string is a valid VUnet ID. A valid VUnet ID consists of 3 letters followed by 3 digits. The letters in the VUnet ID can be written as lower case letters as well as upper case letters.
Examples of valid VUnet IDs are 'ABC123', 'def456', and 'Ghi789'. An example of an invalid VUnet ID is 'ab123c'.
Define functions to structure your program. That is what this assignment is all about!
Hints:
Note: Use only basic coding like vector and so one. Do not use any complicated codes.As well explain evey step.
Correct executions of the program are shown below :
Please enter a vunet id: tKn200 The vunet id tKn200 is valid Please enter a vunet id: tkn2000 error: size incorrect (is 7, should be 6) Please enter a vunet id: ab22cc error: letter expected at position 3 Please enter a vunet id: abcdef error: digit expected at position 4
In: Computer Science
Write the following java program.
Desc: The program computes the cost of parking a car in a public garage at the rate $5.00/hour. The client will always be charged for whole hours. For example, if a car parked for 2 hours and 1 minute, the client will be charged for 3 hours.
Input: User inputs the entry time and exit time in 24-hr clock format (hh:mm)
Output: The enter and exit times, the length of time the car is parked and the total charges.
Note:
Your main program must call method readTime to read Time24 objects.
You must document the main program as well as Time24:
import java.util.Scanner;
import java.util.StringTokenizer;
import java.text.DecimalFormat;
/**
A data structure that stores integer values for hour (0..23) and
minute (0..59) to represent the time of day in a 24-hour
clock
*/
public class Time24 {
private int hour;
private int minute;
//Post: Sets the hour value in the range 0 to 23 and the minute
value in the range 0 to 59
private void normalizeTime()
{
int extraHours = minute / 60;
minute %= 60;
hour = (hour + extraHours) % 24;
}
/**
Desc:Initializes this Time24 object
Post:hour and minute of this Time24 object both initialized to
0
*/
public Time24()
{
this(0,0); //calls the 2-argument constructor of class Time24
}
/**
Desc:Initializes this Time24 object
Pre:h and m cannot be negative
Post:hour and minute of this Time24 object initialized to h and
m
respectively. This operation will normalize the time if necessary
(e.g.
9:75 is stored as 10:15).
Throw:IllegalArgumentException if h or m is negative
*/
public Time24(int h, int m)
{
setTime(h, m);
}
/**
Desc:Sets the hour and minute of this Time24 object to a particular
time
Pre:h and m cannot be negative
Post:hour and minute of this Time24 object set to h and m
respectively. This operation will normalize the time if necessary
(e.g.
9:75 is stored as 10:15).
Throw:IllegalArgumentException if h or m is negative
*/
public void setTime(int h, int m)
{
if (h < 0 || m < 0)
throw new IllegalArgumentException("Time24.setTime: argument"
+ " must not be negative");
this.hour = h;
this.minute = m;
normalizeTime();
}
/**
Desc:Adds minutes to this Time24 object
Pre:m cannot be negative
Post:This Time24 object set to m minutes later. This operation
will
normalize the time if necessary (e.g. 9:75 is stored as
10:15).
Throw:IllegalArgumentException if m is negative
*/
public void addTime(int m)
{
if (m < 0)
throw new IllegalArgumentException("Time24.addTime: argument"
+ " must not be negative");
minute += m;
normalizeTime();
}
/**
Desc:Measures the interval from this Time24 object to another
time
Return:The interval from this Time24 object to t as a Time24
*/
public Time24 interval(Time24 t)
{
int currTime = hour * 60 + minute;
int tTime = t.hour * 60 + t.minute;
if (tTime < currTime)
tTime += 24 * 60;
return new Time24(0, tTime-currTime);
}
/**
Desc:Gets the hour value of this Time24 object
Return:The hour value of this Time24 object
*/
public int getHour()
{
return hour;
}
/**
Desc:Gets the minute value of this Time24 object
Return:The minute value of this Time24 object
*/
public int getMinute()
{
return minute;
}
/**
Desc:Converts this Time24 object to a string
Return:This Time24 object as a String in the form "hh:mm"
*/
public String toString()
{
DecimalFormat f = new DecimalFormat("00");
return hour + ":" + f.format(minute);
}
/**
Desc:Convert a String to a Time24
Pre:s must be in the form "hh:mm" where hh and mm are positive
integers
Return:A Time24 object that corresponds to s
*/
public static Time24 parseTime(String s)
{
StringTokenizer t = new StringTokenizer(s, ":");
int h = Integer.parseInt(t.nextToken());
int m = Integer.parseInt(t.nextToken());
return new Time24(h, m);
}
/**
Desc: Read from f the hour and minute for this Time24 object
Pre: f is ready to be read, and the next line contains hh:mm where
hh:mm gives a valid 24-hour time
Post:The entire line hh:mm read in from f.
The hour and minute of this
Time24 object set to hh and mm respectively.
The operation will normalize the time if
necessary (e.g. 9:75 is stored as 10:15).
*/
public void readTime(Scanner f)
{
String line = f.nextLine();
Time24 obj = parseTime(line);
this.hour = obj.hour;
this.minute = obj.minute;
}
}
In: Computer Science