Questions
convert 0x41BA8000 to IEEE-754 floating-point value

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...

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

How do I change my if statements into while and for loops, so that I can...

How do I change my if statements into while and for loops, so that I can make my bot go straight and turn exactly 12 times.

/***********************************************************************
* Exp7_1_RotaryEncoder -- RedBot Experiment 7_1
*
* Knowing where your robot is can be very important. The RedBot supports
* the use of an encoder to track the number of revolutions each wheels has
* made, so you can tell not only how far each wheel has traveled but how
* fast the wheels are turning.
*
* This sketch was written by SparkFun Electronics, with lots of help from
* the Arduino community. This code is completely free for any use.
*
* 8 Oct 2013 M. Hord
* Revised, 31 Oct 2014 B. Huang
***********************************************************************/

#include <RedBot.h>
RedBotMotors motors;

RedBotEncoder encoder = RedBotEncoder(3,9); // initializes encoder on pins A2 and 10
int buttonPin = 12;
int countsPerRev = 192; // 4 pairs of N-S x 48:1 gearbox = 192 ticks per wheel rev

// variables used to store the left and right encoder counts.
int lCount;
int rCount;

void setup()
{
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(9600);
Serial.println("left right");
Serial.println("================");
}

void turn()

{

long lCount = 0;

long rCount = 0;

long targetCount;

float numRev;

motors.leftMotor(-80);

motors.rightMotor(0);
// variables for tracking the left and right encoder counts

long prevlCount, prevrCount;

long lDiff, rDiff; // diff between current encoder count and previous count

encoder.clearEnc(BOTH); // clear the encoder count

delay(100); // short delay before starting the motors.

while (lCount < 0)

{

// while the right encoder is less than the target count – debug print

// the encoder values and wait – this is a holding loop.

lCount = encoder.getTicks(LEFT);

rCount = encoder.getTicks(RIGHT);

Serial.print(lCount);

Serial.print("\t");

Serial.print(rCount);

Serial.print("\t");

Serial.println(targetCount);

// calculate the rotation “speed” as a difference in the count from previous cycle.

lDiff = (lCount - prevlCount);

rDiff = (rCount - prevrCount);

// store the current count as the “previous” count for the next cycle.

prevlCount = lCount;

prevrCount = rCount;

}

delay(500); // short delay to give motors a chance to respond.
motors.brake();

}


void loop(void)
{
  
// wait for a button press to start driving.

  
if(digitalRead(buttonPin) == LOW)
{
encoder.clearEnc(BOTH); // Reset the counters.
delay(500);
motors.drive(180); // Start driving forward.
}
  

// store the encoder counts to a variable.
lCount = encoder.getTicks(LEFT); // read the left motor encoder
rCount = encoder.getTicks(RIGHT); // read the right motor encoder

// print out to Serial Monitor the left and right encoder counts.
Serial.print(lCount);
Serial.print("\t");
Serial.println(rCount);

// if either left or right motor are more than 5 revolutions, stop
  
if ((lCount >= 5*countsPerRev) || (rCount >= 5*countsPerRev ))
{
  
turn();
encoder.clearEnc(BOTH);
//motors.brake();
delay(500);
motors.drive(180); // Start driving forward.
  
  
}
  
}

In: Computer Science

convert 0x41BA8000 to IEEE-754 floating-point value

convert 0x41BA8000 to IEEE-754 floating-point value

In: Computer Science

Write a JavaFX application that presents a button and a circle. Every time the button is...

Write a JavaFX application that presents a button and a circle. Every time the button is pushed, the circle should be moved to a new random location within the window.

This must only be one .java file. I cannot use

import javafx.geometry.Insets;

import javafx.scene.canvas.Canvas;

import javafx.scene.canvas.GraphicsContext;

import javafx.scene.layout.HBox;

This is what I have so far:

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.shape.Circle;
import javafx.scene.paint.Color;
import javafx.stage.Stage;

public class CircleJumper extends Application
{
public double circlePositionX = 300;
public double circlePositionY = 300;
  
@Override
   public void start(Stage primaryStage)
{
Circle circle = new Circle(circlePositionX, circlePositionY, 70);
circle.setFill(Color.BLUE);

//create button to create new circle
Button push = new Button("PRESS!");
push.setOnAction(this::processButtonPress);
  
  
Group root = new Group(circle, push);
Scene Scene = new Scene(root, 700, 500, Color.WHITE);
  
       primaryStage.setTitle("Circle Jumper"); // Set the stage title
       primaryStage.setScene(Scene); // Place the scene in the stage
       primaryStage.show(); // Display the stage
   }
  
public void processButtonPress(ActionEvent event)
{   
Circle circle = new Circle(Math.random(), Math.random(), 50);
circle.setFill(Color.BLUE);
Group root = new Group(circle);
Scene Scene = new Scene(root, 700, 500, Color.WHITE);
}
  
public static void main(String[] args)
{
launch(args);
}

In: Computer Science

Create, and write, three people's names into an external file named "names.txt."  You should overwrite the file...

  1. Create, and write, three people's names into an external file named "names.txt."  You should overwrite the file if it already exists.
  2. Read those three people's names into the program from the text file and print them out to the end user's console.
  3. Append three more people's names to the external file named "names.txt."
  4. Read those six people's names from the text file into the program and print them out to the end user's console.

Then try:

  • Get the filename from the end user for all file I/O
  • Get the number of names from the end user for all file I/O
  • Use loops to get the names from the end user for all file I/O
  • Use a loop to repeat the program if the end user desires

***

ADDITIONAL NOTES IN CASE YOU ARE HAVING I/O TROUBLES:

//Writing from your Source Code to an External .txt File:
PrintWriter outputFile = new PrintWriter("names.txt");        
outputFile.println("Mike");
outputFile.close();

*************
//Appending from your Source Code to an External .txt File:
FileWriter fileWrite = new FileWriter("names.txt", true);
PrintWriter outWrite = new PrintWriter(fileWrite);
outWrite.println("John");
outWrite.close();

*************
//Reading from an external .txt File into your Source Code:
File myFile = new File("Customers.txt");
Scanner inputFile = new Scanner(myFile);
String str = inputFile.nextLine();
inputFile.close();

In: Computer Science

Use Java to rewrite the following pseudo-code segment using a loop structure without goto, break, or...

Use Java to rewrite the following pseudo-code segment using a loop structure without goto, break, or any other unconditional branching statement:

k = (j+13)/27; //assume i,j,k are integers properly declared.

loop:

if k > 10 then goto out

k=k+1.2;

i=3*k-1;

goto loop;

out: …

In: Computer Science

Given the Linux shell command descriptions, please write down the corresponding shell commands in a terminal...

Given the Linux shell command descriptions, please write down the corresponding shell commands in a terminal window.

            a) list the current directory contents with the long format

            b) print the name of the working directory

            c) change directory to the root directory

            d) change the permissions of file "myfile" (owned by yourself) so that (1)you can read/write, but cannot execute; (2) all other users cannot read/write/execute this file.

            e) make a new directory called “mydir”

In: Computer Science

Are you planning to allow clients to ACCESS YOUR RAW DATA (Big Data) or are you...

Are you planning to allow clients to ACCESS YOUR RAW DATA (Big Data) or are you planning on analyzing that Big Data and presenting FINISHED ANALYTICS to clients?? If you are planning on allowing many many customers to access your data, then how big is your helpdesk and how big does your network throughput need to be to allow customer-access?  And what about Security?  If you're mostly in the cloud - is your CSP going to provide sufficient security?  If you are mostly NOT in the cloud - what's your general plan for Security?

In: Computer Science

Q1) Create a function called max that receives two integer values and returns the value of...

Q1) Create a function called max that receives two integer values and returns the value of the bigger integer.

Q2) Complete the missing code in the following program. Assume that a cosine function has already been created for you. Consider the following function header for the cos function. double cos (double x) #include void output_separator() { std::cout << "================"; } void greet_name(string name) { std::cout << "Hey " << name << "! How are you?"; } int sum(int x, int y){ return x + y; } int main() { std::string name; int num1, num2, result; double num_dec, result_dec; std::cout << "Please enter your name: "; std::cin >> name; Answer ; // call the greet_name function and pass the user's name Answer ; // call the output_separator function std::cout << "Please input 2 integer values: "; std::cin >> num1 >> num2; std::cout << "Please input a double value: "; std::cin >> num_dec; std::cout << "Here are the results of my function test"; Answer ; // store the result of the sum function into // result and pass num1 and num2 as parameters std::cout << "Sum result: " << result; Answer ; // store the result of the cos function into // result_dec and pass num_dec as the parameter std::cout << "Cosine result: " << result_dec; return 0; }

In: Computer Science

PYTHON The nth term of the sequence is given by: Xn = (2 ∗ Xn-3) +Xn-2+/...

PYTHON

The nth term of the sequence is given by: Xn = (2 ∗ Xn-3) +Xn-2+/ + (4 ∗ Xn-1)

For example, if the first three values in the sequence were 1, 2 and 3. The fourth value would be: (2 * 1) + 2 + (4 * 3) = 16 Replacing the previous three Integers (2, 3 and 16) in the formula would determine the fifth value in the sequence. The nth term can be calculated by repeating this process. Write a program that includes two functions main() and calculate()which are used to determine the nth term in the sequence.

The main() function: • Displays a description of the program’s function • Prompts the user for the number of values in the sequence (n) • Prompts the user for the first three values in the sequence • Using a loop, calls the calculate() function repeatedly until the nth value is determined • Displays the nth value of the sequence

The calculate() function: • Accepts three values as arguments • Calculates the next value in the sequence • Returns the calculated value

In: Computer Science

Complete these steps to write a simple calculator program: 1. Create a calc project directory 2....

Complete these steps to write a simple calculator program:

1. Create a calc project directory

2. Create a mcalc.c source file containing five functions; add, sub, mul, div, and mod; that implement integer addition, subtraction, multiplication, division, and modulo (remainder of division) respectively. Each function should take two integer arguments and return an integer result.

3. Create a mcalc.h header file that contains function prototypes for each of the five functions implemented in mcalc.c.

4. Create a calc.c source file with a single main function that implements a simple calculator program with the following behavior:

-> Accepts a line of input on stdin of the form ”number operator number” where number is a signed decimal integer, and operator is one of the characters ”+”, ”-”, ”*”, ”/”, or ”%” that corresponds to the integer addition, subtraction, multiplication, division, and modulo operation respectively.

-> Performs the corresponding operation on the two input numbers using the five mcalc.c functions.

-> Displays the signed decimal integer result on a separate line and loops to accept another line of input.

-> Or, for any invalid input, immediately terminates the program with exit status 0.

5. Create a Makefile using the following Makefile below as a starting point. Modify the Makefile so that it builds the executable calc as the default target. The Makefile should also properly represent the dependencies of calc.o and mcalc.o.

CC = gcc
CFLAGS = -g -O2 -Wall -Werror
ASFLAGS = -g

objects = calc.o mcalc.o

default: calc

.PHONY: default clean clobber

calc: $(objects)
   $(CC) -g -o $@ $^

calc.o: calc.c mcalc.h


%.o: %.c
   $(CC) -c $(CFLAGS) -o $@ $<

%.o: %.s
   $(CC) -c $(ASFLAGS) -o $@ $<

clean:
   rm -f $(objects)

clobber: clean
   rm -f calc

6. Compile the calc program by executing ”make” and verify that the output is proper. For example:

# ./calc

3 + 5

8

6 * 7

42

In: Computer Science

Write and test a python program to demonstrate TCP server and client connections. The client sends...

Write and test a python program to demonstrate TCP server and client connections. The client sends a Message containing the 10 float numbers (FloatNumber[]) , and then server replies with a message containing maximum, minimum, and average of these numbers.

In: Computer Science

I need this code translated to C code. Thank you. public class FourColorTheorem { public static...

I need this code translated to C code. Thank you.

public class FourColorTheorem {


public static boolean isPrime(int num) {
// Corner case
if (num <= 1)
return false;
// Check from 2 to n-1
for (int i = 2; i < num; i++)
if (num % i == 0)
return false;
return true;
}

public static void main(String[] args) {

int squares[] = new int[100];
for (int i = 1; i < squares.length; i++) squares[i-1] = i * i;

int n = 5;
while (true) {
boolean flag = false;
for (int i = 0; i < squares.length; i++) {
int difference = n - 2 * squares[i];

if (isPrime(difference)) {
flag = true;
// you can comment the below line
System.out.println(n + " = " + difference + " + 2*" + Math.sqrt(squares[i]) + "*" + Math.sqrt(squares[i]));
break;
}
}
if (!flag) {
break;
}
n += 2;
}

System.out.println("Smallest counter example = " + n);
}
}

In: Computer Science

In the PDF file that will contain your screen shots, explain what is wrong with the...

In the PDF file that will contain your screen shots, explain what is wrong with the code below. Do not just state thing like “line 3 should come after line 7,” you must explain why it needs to be changed. This shows that you are fully understanding what we are going over.

// This program uses a switch-case statement to assign a

// letter grade (A, B, C, D, or F) to a numeric test score.

#include <iostream>

using namespace std;

int main()

{

double testScore;

cout<< "Enter your test score and I will tell you\n";

cout<<"the letter grade you earned: ";

cin>> testScore;

switch (testScore)

{

case (testScore < 60.0):

cout << "Your grade is F. \n";

break;

case (testScore < 70.0):

cout << "Your grade is D. \n";

break;

case (testScore < 80.0):

cout << "Your grade is C. \n";

break;

case (testScore < 90.0):

cout << "Your grade is B. \n";

break;

case (testScore < 100.0):

cout << "Your grade is A. \n";

break;

default:

cout << "That score isn't valid\n";

return 0;

}

In: Computer Science