Questions
File Compare Write a program that opens two text files and reads their contents into two...

File Compare
Write a program that opens two text files and reads their contents into two separate
queues. The program should then determine whether the files are identical by comparing
the characters in the queues. When two nonidentical characters are encountered,
the program should display a message indicating that the files are not the same. If both
queues contain the same set of characters, a message should be displayed indicating
that the files are identical.

// Copyright (c) 2013 __Pearson Education__. All rights reserved.

/** ADT queue: Link-based implementation.

Listing 14-3.

@file LinkedQueue.h */

#ifndef _LINKED_QUEUE

#define _LINKED_QUEUE

#include "QueueInterface.h"

#include "Node.h"

#include "PrecondViolatedExcep.h"

template<class ItemType>

class LinkedQueue : public QueueInterface<ItemType>

{

private:

   // The queue is implemented as a chain of linked nodes that has

   // two external pointers, a head pointer for front of the queue and

   // a tail pointer for the back of the queue.

   Node<ItemType>* backPtr;

   Node<ItemType>* frontPtr;

public:

   LinkedQueue();

   LinkedQueue (const LinkedQueue& aQueue);

   ~LinkedQueue();

       bool isEmpty() const;

       bool enqueue(const ItemType& newEntry);

       bool dequeue();

  

   /** @throw PrecondViolatedExcep if the queue is empty */

       ItemType peekFront() const throw(PrecondViolatedExcep);

}; // end LinkedQueue

#include "LinkedQueue.cpp"

#endif

In: Computer Science

Modified from Chapter 07 Programming Exercise 5 Original Exercise: Rock, Paper, Scissors Modification Programming Exercise 11...

Modified from Chapter 07 Programming Exercise 5

Original Exercise:

Rock, Paper, Scissors Modification
Programming Exercise 11 in Chapter 6 asked you to design a program that plays the Rock, Paper, Scissors game. In the program, the user enters one of the three strings—"rock", "paper", or "scissors"—at the keyboard. Add input validation (with a case-insensitive comparison) to make sure the user enters one of those strings only.

Modifications:

  • Allow the user to input "r", "p", "s" or the full strings "Rock", "Paper", "Scissors"
    • Allow the user to input upper or lowercase
    • try the following:
      • input = input.lower()
  • Refer to the following code to help generate a random computer player action
    • import random
      pc_choice_list = ["rock", "paper", "scissors"]
      pc_choice = random.choice(pc_choice_list)
  • Allow the player to input a "q" for their turn if they want to quit the game
  • Use loops not only to validate the input but also to keep the game running as long as the player does not input a "q" on their turn
  • Example outputs
    • Rock beats Scissors
    • Paper beats Rock
    • Scissors beats Paper
    • Tie
    • Game Over
    • Let's Play Rock, Paper, Scissors
      Input your choice: r,p, or s

Turn IN:

Raptor flowchart file (or alternative flowchart screenshot)
        If you are on Windows please try using the built-in "Snip & Sketch" program to take a perfectly sized screenshot.
Thonny Python file (or Python file is written in any IDE/program)
        Turn in the actual Python code file "file_name.py"

In: Computer Science

Program in C: The strncpy(s1,s2,n) function copies exactly n characters from s2 to s1, truncating s2...

Program in C:

The strncpy(s1,s2,n) function copies exactly n characters from s2 to s1, truncating s2 or padding it with extra null characters as necessary. The target string may not be null-terminated if the length of s2 is n or more. The function returns s1. Write your own version of this function. Test the function in a complete program that uses a loop to provide input values for feeding to the function.

In: Computer Science

In C# thanks please, Design a class named Person with properties for holding a person’s name,...

In C# thanks please,

Design a class named Person with properties for holding a person’s name, address, and telephone number.

Design a class named Customer, which is derived from the Person class. The Customer class should have the variables and properties for the customer number, customer email, a spentAmount of the customer’s purchases, and a Boolean variable indicating whether the customer wishes to be on a mailing list. It also includes a function named calcAmount that calculates the spentAmount.

All retail store has a preferred customer plan where customers can earn discounts on all their purchases. The amount of a customer’s discount is determined by the amount of the customer’s cumulative purchases in the store as follows:

  • When a preferred customer spends $500, he or she gets a 5% discount on all future purchases.
  • When a preferred customer spends $1000, he or she gets a 6% discount on all future purchases.
  • When a preferred customer spends $1500, he or she gets an 8% discount on all future purchases.
  • When a preferred customer spends $2000, he or she gets a 10% discount on all future purchases.

Design a class named PreferredCustomer, which is derived from the Customer class. The PreferredCustomer class should have a variable, discountLevel, with a read-only property. It alsoincludes a setDiscountLevel function that determine the discount level based on the purchases amount using switch statement and an override function, calcAmount, calculates the spentAmount with the current discount level.

Create a CustomerDemo class. In the main function, the program calls the getData function to read the data from the “CustomerInfo.txt” file and create a dynamic array of PreferredCustomer object.  Then, it prompts user to enter a customer number and displays a menu:

  1. Display Customer Information: display the specific customer information
  2. Update Spent Amount: update the total amount with the correct discount level

After update the spent Amount, the program writes the updated information back to file.

Example for customer info.txt below (there are 5 persons)

Kyle Jones

879 hobbs st. boston,MA 84758

456-789-0001

JLA9876A

[email protected]

3000

true

.

.

.

.

In: Computer Science

Consider five-card-hands out of a deck of 52 cards. a) (10%) What is the probability that...

Consider five-card-hands out of a deck of 52 cards.

a) (10%) What is the probability that a hand selected at random contains five cards of the same suit? (The suits are hearts, spades, diamonds and clubs.) Show a formula and compute a final answer. Show your intermediate computations.

b) (10%) In how many different ways can a hand contain no more than 2 cards of the same kind. (E.g. not more than 2 queens.) Show a formula but you do not have to compute a final answer.

In: Computer Science

5. Modify the program for Line Numbers from L09: In-Class Assignment. Mainly, you are changing the...

5.

Modify the program for Line Numbers from L09: In-Class Assignment. Mainly, you are changing the

problem from using arrays to ArrayLists. There are some other modifications as well, so read the instructions carefully.

The program should do the following:

–Ask the user for how many lines of text they wish to enter

–Declare and initialize an **ArrayList** of Strings to hold the user’s input

–Use a do-while loop to prompt for and read the Strings (lines of text) from the user

at the command line until they enter a sentinel value

–After the Strings have been read, use a for loop to step through the ArrayList of

Strings and concatenate a number to the beginning of each line eg:

This is change to 1 This is

The first day change to 2 The first day

and so on…

–Finally, use a **for each** loop to output the Strings (numbered lines) to the command

line.

*/

Below is L09 in-class assignment for part 5

2. Create a new program. This is the program you will submit for points today.

Write a Java code snippet to do the following:
– Declare and allocate an ArrayList of Strings
– Use a do-while loop to prompt for and read the Strings (lines of text)
from the user at the command line until they enter a sentinel value.
- Use a for loop to step through the ArrayList and concatenate a line number
to the beginning of each line eg:

This is change to 1 This is

The first day change to 2 The first day

and so on…

– Finally, use a for loop to output the Strings (numbered lines) to the command line.

*/
Scanner scnr = new Scanner(System.in);
System.out.println("How many lines of text do you want to enter?");
  
int numLines = 0;
numLines = scnr.nextInt();
System.out.println();
  
String [] arrayLines = new String[numLines];
scnr.nextLine();
  
int i = 0;
while(i < numLines)
{
System.out.println("Enter your text: ");
String text = scnr.nextLine();
arrayLines[i] = text;
i++;
}
  
for(i = 0; i < numLines; i++)
{
arrayLines[i] = (i + 1) + " " + arrayLines[i];
}
  
for(String element: arrayLines)
{
System.out.println(element);
}
}
  
}

In: Computer Science

Change Calculator Task: Create a program that will input a price and a money amount. The...

Change Calculator

Task:

Create a program that will input a price and a money amount. The program will then decide if there is any change due and calculate how much change and which coins to hand out. Coins will be preferred in the least number of coins (starting with quarters and working your way down to pennies).

Input:

total_price, amount_tender
allow the user to input 'q' for either value if they want to quit the program

Validate:

total_price

  • cannot be negative
  • cannot be 0
  • cannot be text (other than q for quit)

amount_tender

  • cannot be less than total_price
  • can be equal to total_price
  • cannot be text (other than q for quit)

Output:

change_amount
number_quarters
number_dimes
number_nickels
number_pennies

IF any of these values is zero, DO NOT output that value. IE: if the change is 26 cents you only need to tell the user they will receive 1 quarter and 1 penny. No more, no less.

Hint:

Use modular division to track the remainder after calculating each number of coins.

Convert the decimal to a whole number to make the calculation easier. Use math.floor() to round DOWN to the nearest integer.

Use a try-catch (try-except) to help validate input. Try to set the input value into afloat and if it does not fit then you can test the input further without an error stopping your program.

Requirements:

Use a function

Use a loop

Validate all input

Use an IF statement

Use helpful, human-readable text both to prompt for input, but also to let the user know about invalid inputs. Simply stating it is invalid doesn't help the user to correct their error.

If you can make your program also calculate the number of dollars for change. That is, change above 99 cents.

Turn IN:

Python file ONLY

In: Computer Science

Smaller index Complete the following function according to its docstring using a while loop. The lists...

Smaller index

Complete the following function according to its docstring using a while loop. The lists we test will not all be shown; instead, some will be described in English. If you fail any test cases, you will need to read the description and make your own test.

def smaller_index(items):
""" (list of int) -> int
  
Return the index of the first integer in items that is less than its index,
or -1 if no such integer exists in items.
  
>>> smaller_index([2, 5, 7, 99, 6])
-1
>>> smaller_index([-5, 8, 9, 16])
0
>>> smaller_index([5, 8, 9, 0, 1, 3])
3
"""

In: Computer Science

make multiply function with ‘add’ command, Convert to mips code Don’t use ‘mult’ Use 'add' multiple...

make multiply function with ‘add’ command,

Convert to mips code

Don’t use ‘mult’

Use 'add' multiple times

Get input from key-board and display the result in the console window

In: Computer Science

Just need java code for a small business that books shows and gives out a receipt...

Just need java code for a small business that books shows and gives out a receipt after placing order on what show they want

In: Computer Science

Consider the following grammar G: E -> E + T | T T -> T F...

Consider the following grammar G:
E -> E + T | T
T -> T F | F
F -> F* | a | b

This grammar can be used to generate regular expressions over the alphabet {a,b} with standard precedence rules.
Show your solution for each of the following 5 points:

    1. Remove left recursion and write the resulting grammar G1.
    2. For the grammar G1, compute and write the sets FIRST for every right hand side of every production,
       and the sets FOLLOW for every left hand side (i.e. any non-terminal).
    3. Find and write the table for a predictive parser
    4. Is G1 LL(1)? Justify your answer.
    5. If the answer to (4) above is yes, then trace parsing of: a* + ab*

In: Computer Science

in JAVA PLEASE SHOW OUTPUT! PriorityQueueUserDefinedObjectExample (20) Create an Employee class which implements Comparable<Employee> The constructor...

in JAVA PLEASE SHOW OUTPUT!

  1. PriorityQueueUserDefinedObjectExample (20)

Create an Employee class which implements Comparable<Employee>

The constructor consists of an employee’s first name and an employee’s salary, both of which are instance variables.

Create accessor and mutator methods for both of these variables

Write an equals method that returns true if the salaries are equal with one cent and the names are exactly equal

Write a compareTo method that returns 1 if the salary of this employee is greater than the salary of the comparable, -1 if less than and 0 if equal.

Create a class called PriorityQueueUserDefinedObjectExample

Create a Scanner to read from the user input.

Create a Scanner and a PrintWriter to read to a file and output to a different file. (note: You should prompt for the names of these files).

The input file has a single name followed by a 5 or 6 figure salary on each line. (You can use my empsalaries.txt in the homework for Lesson 7)

Create a PriorityQueue

Read in and add each employee to the queue

Use the remove method as you write the employee and salary to the output file from lowest salary to highest.

See sample input file empsalaries.txt and output file priorityemp.txt

//empsalaries

James 1000000.42
Oscar 7654321.89
Jose 352109.00
Daniel 98476.22
Juan 452198.70
Sean 221133.55
Ryan 1854123.77

//priorityemp

    NAME           SALARY
  Daniel        $ 98476.22
    Sean        $221133.55
    Jose        $352109.00
    Juan        $452198.70
   James        $1000000.42
    Ryan        $1854123.77
   Oscar        $7654321.89

In: Computer Science

How LUNCH meterpreter in Kali Linux. Complete command please. Thank you

How LUNCH meterpreter in Kali Linux. Complete command please. Thank you

In: Computer Science

Have you heard about Software Defined Networking (SDN)? If not, please do some research and find...

Have you heard about Software Defined Networking (SDN)? If not, please do some research and find out about SDN and discuss briefly at least two advantages of using SDN.

In: Computer Science

Given some data in a text file, the task is to scramble the text and output...

Given some data in a text file, the task is to scramble the text and output in a separate text file. So, we need to write a Python program that reads a text file, scrambles the words in the file and writes the output to a new text file.

Rules to be followed:

  • Words less than or equal to 3 characters need not be scrambled.
  • Don’t scramble first and last char, so Scrambling can become Srbmnacilg or Srbmnailcg or Snmbracilg, i.e. letters except first and last can be scrambled in any order.
  • Punctuation at the end of the word to be maintained as is i.e. “Surprising, ” could become “Spsirnirug, ” but not “Spsirn, irug”

In: Computer Science