Questions
(6 marks- 3 marks each) The following hexadecimal values are shorthand for 16-bit two’s complement binary...

(6 marks- 3 marks each) The following hexadecimal values are shorthand for 16-bit two’s complement binary numbers. Working purely in hex, negate each and then state whether the result is positive or negative.

(a) 5E91

(b) D00F 2.

In: Computer Science

C++ Zybook Lab 16.5 LAB: Exception handling to detect input string vs. int The given program...

C++ Zybook Lab 16.5 LAB: Exception handling to detect input string vs. int

The given program reads a list of single-word first names and ages (ending with -1), and outputs that list with the age incremented. The program fails and throws an exception if the second input on a line is a string rather than an int. At FIXME in the code, add a try/catch statement to catch ios_base::failure, and output 0 for the age.

Ex: If the input is:

Lee 18
Lua 21
Mary Beth 19
Stu 33
-1

then the output is:

Lee 19
Lua 22
Mary 0
Stu 34

Here's the code:

#include <string>
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
string inputName;
int age;
// Set exception mask for cin stream
cin.exceptions(ios::failbit);

cin >> inputName;
while(inputName != "-1") {
// FIXME: The following line will throw an ios_base::failure.
// Insert a try/catch statement to catch the exception.
// Clear cin's failbit to put cin in a useable state.
try{
//Reading age
cin >> age;
//Printing Name and age incremented by 1 if correct values are entered
cout << inputName << " " << (age + 1) << endl;
}
catch(ios_base::failure){
//Clear cin
cin.clear();
}
  
cin >> age;
cout << inputName << " " << (age + 1) << endl;

cin >> inputName;
}

return 0;
}

In: Computer Science

Java Project Requirements: 1.Write a Java program that plays a word game with a user. The...

Java

Project Requirements:

1.Write a Java program that plays a word game with a user. The program asks the user questions and then creates a paragraph using the user’s answers.

2.The program must perform the following:

a.Uses a Scanner object to ask the user: (The program asks for no other information)

i.Full Name (First and Last name only) - stores this Full Name in one String object variable.

ii.Age – must be read in as an int.

iii.Profession or expected profession

iv.Name of favorite pet

v.Cost of their first vehicle – must be read in as a double.

b.All input data must be stored in their own variable prior to printing out.

c.Display a paragraph of the programmer’s choosing that contains the following

i.The user’s full name, first name, and last name in separate places in the paragraph, such as James Gosling founded Sun Microsystems. James was a child prodigy. The Gosling family is very proud of James.

ii.The user’s age.

iii.The user’s profession in all uppercase regardless of the case the profession was entered.

iv.The user’s favorite pet’s name in all lower case regardless of the case the name was entered.

v.The total cost of the user’s first vehicle in a rounded two decimal places including the dollar signs. The total cost must include the inputted cost plus a 7.5% sales tax. The sales tax rate is stored as a constant in the program.

vi.A statement in parenthesis stating the total number of characters in the paragraph such as (The above story contained 345 characters)

d.Include javadoc class comment following Project Comment Template on the content page.

3.The project requires one files to be turned in - WordGame.java (the source code of your Word Game programming.

In: Computer Science

write a fully-connected neural network to work with MNIST and Tensorflow 2.x. The labels will be...

write a fully-connected neural network to work with MNIST and Tensorflow 2.x. The labels will be input and MNIST image vectors as output labels. use tf.GradientTape instead fit. show the 28x28 image with the input vector.

PLEASE WRITE CODE AND DO NOT SENT ME DIFFERENT PARTS TO A WEBSITE.

It is clear, it's a homework assignment.  

In: Computer Science

IN PROGRAMMING LANGUAGE C -I am trying to alphbetize a string in descending or to EX...

IN PROGRAMMING LANGUAGE C

-I am trying to alphbetize a string in descending or to

EX

INPUT: B C D A

OUTPUT:

D

C

B

A

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main(int argc, char*argv[])
{


        int MAX = 100000;
        int i =0;
        int k =0;
        int j =0;
        char array[MAX];
        char split[] = " ,.-!?()0123456789";
        int n = 0;
        char second[MAX];
        printf("Please enter in a String: ");
        //String input
        fgets(array,MAX,stdin);

        char **first =(char**)malloc(sizeof(char*));
        char *token = strtok(array,split);

        while(token!= NULL)
        {

                k = strlen(token);
                first=(char **)realloc(first,(n+1)*sizeof(char));
                first[n] = (char *)malloc((k+1)*sizeof(char));
                memcpy(first[n],token,k*sizeof(char));
                token = strtok(NULL,split);
                n++;

        }

        second = sortedArray(first,n);
        for(i =0; i<n;i++)
        {
         printf("%s",second[i]);
        }


        return 0;

}

char *sortedArray(char *sortRay[], int size)
{
        int i =0;
        int j =0;
        char temp[300];
        for(i =0; i<size; i++)
        {
          for(j =i +1; j<size;j++)
           {
             if(strcmp(sortRay[i],sortRay[j])>0)
            {
             strcpy(temp,sortRay[i]);
             strcpy(sortRay[i],sortRay[j]);
             strcpy(sortRay[j],temp);
            }
           }
        }
        return sortRay;
}

In: Computer Science

You can only use built in Lisp functions and you cannot use setq function. Write a...

You can only use built in Lisp functions and you cannot use setq function.

Write a function in Lisp called f1 that counts the number of lists in a list. Example: (f1 ‘(a (a b (b c)) c d (e))) returns 2

In: Computer Science

Q3. (Real World Research) Mom in our MP store is concerned about customer records and maintaining...

Q3. (Real World Research) Mom in our MP store is concerned about customer records and maintaining the integrity of their records and the other stores they currently own.

Objective: Create a simple 150-word report.

In: Computer Science

Stack2540Array   import java .io .*; import java . util .*; public class Stack2540Array { int CAPACITY...

Stack2540Array  

import java .io .*;
import java . util .*;
public class Stack2540Array {
int CAPACITY = 128;
int top ;
String [] stack ;
public Stack2540Array () {
stack = new String [ CAPACITY ];
top = -1;
}
1

public int size () { return top + 1; }
public boolean isEmpty () { return (top == -1); }
public String top () {
if ( top == -1)
return null ;
return stack [ top ];
}
public void push ( String element ) {
top ++;
stack [top ] = element ;
}

3.2 Dynamic Array
To save computer memory, we need to use dynamic array. In the rst version of our stack implementation, the instance variable has a
xed capacity, which is 128. There will be an error when the stack is bigger than 128. For bigger data, you increased the array size. But
that very long array could be wasted for smaller data.

in java please.

In: Computer Science

Consider the following code: void swap(int arr[], int i, int j) {        int temp = arr[i];...

Consider the following code:

 

void swap(int arr[], int i, int j) {

       int temp = arr[i];

       arr[i] = arr[j];

       arr[j] = temp;

}

void function(int arr[], int length)

{

       for (int i = 0; i<length / 2; i++)

              swap(arr, i, (length / 2 + i) % length);

}

If the input to the function was 
   int arr[] = { 6, 1, 8, 2, 5, 4, 3, 7 };
   function(arr,8);
What values would be stored in the array after calling the function?

What is the output of the following code?  (as always indicate "error" if there is any kind of runtime or compile-time error or "infinite" if there is an infinite loop)

 

void swap(int &a, int &b)

{

       int t = a;

       a = b;

       b = t;

}

void function(int arr[], int arr2[], int length)

{

       for (int i = 0; i<length; i++)

       {

              swap(arr[i], arr[(i + arr2[i]) % length]);

       }

}

int main()

{

       int arr1[] = { 5, 2, 3, 7, 1, 6, 8, 4 };

       int arr2[] = { 1, 4, -2, -1, 2, 7, 2, 1 };

       function(arr1, arr2, 8);

       for (int a : arr1)

              cout << a << " ";

}

In: Computer Science

On rare occasions, computers have been designed which use one’s complement base 2 representation. Consider the...

On rare occasions, computers have been designed which use one’s complement base 2 representation. Consider the decimal expression below: 7 + (-3)= 4

(a) Convert all three numbers to 4-bit one’s complement base 2.

(b) Perform the one’s complement base 2 operation and verify that the sum is as expected.

In: Computer Science

Consider the following splay tree: Show the paths from root to node 12, 10, 9, 5,...

Consider the following splay tree:

Show the paths from root to node 12, 10, 9, 5, and 1 after search node 3. (Sample answer: for the above splay tree, the path from root to node 9 can be expressed as 10, 4, 6, 8, 9.)

The path from root to node 12:Question Blank.The path from root to node 10:Question Blank.The path from root to node 9:Question Blank.The path from root to node 5:Question Blank.The path from root to node 1:Question Blank

In: Computer Science

In this program, you are modifying given code so that the class is object-oriented. 2. Write...

In this program, you are modifying given code so that the class is object-oriented.

2. Write a Java class called CityDistancesOO in a class file called CityDistancesOO.java.   

3. Your class will still make use of two text files. a. The first text file contains the names of cities with the first line of the file specifying how many city names are contained within the file.   

b. The second text file contains the distances between the cities in the file described above without containing an entry for how many distances are within the file.   



4. The CityDistancesOO class will have two class attributes: a. The first attribute, called cities, is a one-dimensional array of String containing the city names. b. The second attribute, called distances, is a two-dimensional array (n x n array where n is the number of cities) of double and organized such that each row corresponds to the distances from a particular city.   

5. The CityDistancesOO class contains a constructor and four non-static methods: c. The constructor takes two arguments both of type String. The first argument, called nameFile, is the file name of the list of city names. The second argument, called distanceFile, is the file name of the list of city distances. The constructor then calls the helper methods loadCities() and loadDistances() to create and populate the two class attributes. d. The method called loadCities() is a helper method and should be private. The method takes a single argument called filename of type String that is the name of the file containing the city names. This method opens the file, reads in the data into cities attribute. The first item read from the text file should be the number of city names within the file (read as an integer). If done correctly, the cities attribute should be the correct size to store all city names without any “extra” space within the array. If the file does not exist or a problem reading the file is encountered, then an IOException is thrown. Hint: Be aware that using the nextInt() method from the Scanner class will read the number but not the newline character found after the number. Your method should correctly handle the newline character.

e. The method called loadDistances() is a helper method and should be private. The method takes an argument called filename of type String that is the name of the file containing the list of distances. The method opens the file, reads in the data into the distances attribute. If the file does not exist or a problem reading the file is encountered, then an IOException is thrown.

f. A public method called getNumberOfCities() that returns the number of cities stored in the cities attribute.

g. A private method called getCityIndex() that takes a single argument called cityName of type String (that is, the name of a particular city). The method iterates through the cities attribute and returns the index of the location within the array that contains the value of cityName. If the string specified by cityName is not found in cities, then the method returns the value -1.


h. A public method called getCity() that takes a single argument called index of type int. This method returns the city name as a String corresponding to the provided index.

i. A public method called findDistance that takes two arguments: the first is called start of type String; and the second is called end of type String. The method makes use of the getCityIndex() helper method to retrieve the indices of the city names corresponding to start and end arguments. Then, the correct distance is retrieved from the distances attribute and returned to the caller.

Given Code:

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class CityDistances {
  

public static String[] loadCities(String filename) throws IOException{

Scanner fileIn = new Scanner(new File(filename));
int n = fileIn.nextInt();
String[] cities = new String[n];

fileIn.nextLine();

int i = 0;
while (fileIn.hasNextLine()) {
cities[i] = fileIn.nextLine();
i++;
}

fileIn.close();

return cities;

}
  
  
public static double[][] loadDistances(String filename,int numCities) throws IOException{

double distances[][] = new double[numCities][numCities];
Scanner fileIn = new Scanner(new File(filename));

for (int i = 0; i < numCities; i++) {
for (int j = 0; j < numCities; j++) {

distances[i][j] = fileIn.nextDouble();

}

}

fileIn.close();

return distances;

}


private static int getCityIndex(String[] cities,String cityName){
int cityIndex = -1;
  
for(int i = 0; i < cities.length ; i++){
if(cities[i].equals(cityName)){
cityIndex = i;
break;
}
}
  
return cityIndex;
}
  


public static double findDistance(String[] cities, double[][] distances,String start,String end){
  
int startCityIndex = getCityIndex(cities, start);
int endCityIndex = getCityIndex(cities, end);

if(startCityIndex!=-1 && endCityIndex!=-1){
return distances[startCityIndex][endCityIndex];
}else{
return -1;
}
}
}

In: Computer Science

Using Tkinter for GUI, A Python program that will allow the user to perform (i) generate...

Using Tkinter for GUI, A Python program that will allow the user to perform (i) generate RSA keys, (ii) encrypt a given message and (iii) decrypt the message without using any cryptographic library. Your program will generate the values of p unless the user provides them manually. Then the program will generate the keys (private and public). Then the program will allow the user to enter his/her message to be encrypted. Finally, the program will perform the decryption operation as well. Subtask and mark distribution:

• Friendly and logical GUI [5 marks]

• Key generation [8 marks]

• Encryption [3 marks]

• Decryption [3 marks]

• Performance enhancement [8 marks] : Due to the limitation of the size of integer type variables, many operations such as xy, xy etc. would not be possible when the value of x, y will be very high. Hence, you would not be able to work with big prime numbers. By definition, this will provide a weak RSA. Under this task you have to optimize the algorithm and implementation to support bigger number. You have to include an extra section in the report to explain how you have achieved this enhancement.

NOTE: User should be able to use the GUI to encrypt/decrypt the message. The task is more like making an app for encryption/decryption using Tkinter.

In: Computer Science

You have been asked to create a python program that will ask the user how many...

You have been asked to create a python program that will ask the user how many tickets the user would like to purchase for graduation. The user will then choose the number of tickets needed and the program will list the cost of the tickets, a service fee, tax, and the total of the purchase.

Specifications:

  • The program should only accept whole numbers when receiving input for the number of tickets needed.
  • No calculations should be performed if input is invalid.
  • No output should be displayed if input is invalid.
  • The service fee should be $2.50 per ticket.
  • The tax should be 3% of the cost of the tickets (without the service fee).
  • The final cost (grand total) should be displayed with a dollar sign and two decimal places.

In: Computer Science

Arrays Assignment in Java 1. Suppose you are doing a report on speeding. You have the...

Arrays Assignment in Java

1. Suppose you are doing a report on speeding. You have the data from 10 different people who were speeding and would like to find out some statistics on them. Write a program that will input the speed they were going. You may assume that the speed limit was 55. Your program should output the highest speed, the average speed, the number of people who were between 0-10 miles over, the number between 10 and 20, and the number over 20. Your program should print out these results.

2. Create a list of 100 randomly generated numbers (between 1 and 100). Print the list out in order, print the list out in reverse order, print out how many of each number was generated.

In: Computer Science