Questions
This task is solved in Python 3. Develop a program that can change the phone number...

This task is solved in Python 3.

Develop a program that can change the phone number of a person in phone.txt (hint: the easiest thing is probably to make a new version of the file, and then delete the old one before the new is renamed to phone.txt)

Name: John

Old phone number: 99776612

New number: 99889999

>>>

phone.txt

Replaced by ------>

phone.txt

Mary 98654321

June 99776655

Chris 99112233

Viv 98554455

John 99776612

Joe 97888776

Rick 99455443

Susan 98122134

Jill 99655732

Bob 98787896

Mary 98654321

June 99776655

Chris 99112233

Viv 98554455

John 99889999

Joe 97888776

Rick 99455443

Susan 98122134

Jill 99655732

Bob 98787896

In: Computer Science

Write the program WritePatientRecords that allows a doctor’s staff to enter data about patients and saves...

Write the program WritePatientRecords that allows a doctor’s staff to enter data about patients and saves the data to a file called Patients.txt. The output should be in the following format: p#, PATIENT_NAME, BALANCE. Create a Patient class that contains fields for ID number, name, and current balance owed to the doctor’s office.

using System;
using static System.Console;
using System.IO;
class WritePatientRecords
{
static void Main()
{
// Your code here
}
}

In: Computer Science

Create the following classes and show a “Hierarchical” relationship between them:           Company, Products and Employee...

Create the following classes and show a “Hierarchical” relationship between them:     

     Company, Products and Employee   

  • Define at least 2 instance variables of these classes.
  • company: company_code, company_name
  • Employee: employee_ name, number_of_employees.
  • Choose the appropriate members for Products by your own understanding.
  • Write default and overloaded constructors for each class
  • Include a method in all the classes by the same name that overrides the direct or indirect base classes.

In: Computer Science

Problem Description Objective This practical will test your capability of implementing a linked list. Design Think...

Problem Description

Objective

This practical will test your capability of implementing a linked list.

Design

Think of how you are going to solve the problem and test your implementation with the test cases you designed based on the stages below.

Testing Hint: it’s easier if you test things as a small piece of code, rather than building a giant lump of code that doesn’t compile or run correctly. As part of your design, you should also sketch out how you are going to build and test the code.

Problem

Linked lists are dynamic data structures that allow storing a list of items in separate places in the memory. Each item of the list, together with the address of the next item, is placed in one object of type Node (find the description below). The last node of the list should include the last item and a null pointer (NULL or nullptr).

Lists, as abstract data types, can be implemented by different structures, including arrays, vectors and linked lists. Please do not use arrays or vectors for this practical. In this practical, you should write the code for two classes named LinkedList, and Node.

You must include separate header and implementation files for both classes. The class Node should consist of two member variables, an integer data and a pointer to Node next, and 5 functions, a constructor, and getter and setter for the two member variables.

The class LinkedList must have only one member variable: head, which is of type pointer to Node. If the list is empty, head should contain NULL or nullptr. It should also have at least the following member functions. Note that add functions should construct nodes from the heap, and delete functions should manually delete the one that is removed from the list. Don’t forget to write test cases for each function and ensure that the tests pass before progressing to the next function.

  • void addFront(int newItem) : The function inserts a new node, containing the newItem, at the beginning of the list.
  • void addEnd(int newItem) : The function inserts a new node, containing the newItem, at the end of the list.
  • void addAtPosition(int position, int newItem) : The function inserts a new node, containing the newItem, such that it is the position-th member of the list. i.e. we assume the first element of the list is in position 1. If position is larger than the size of the list, the new item is added to the end of the list. If position < 1, the new item is added at the beginning of the list.
  • int search(int item) : The function searches the list for the first instance of the item, and if found, both prints the position of the of the item (followed by a space) and returns the position of the item in the list (positions start from 1). If not found, both prints 0 (followed by a space) and returns 0. Note that the returning type is different from what was explained in the search function in the lecture.
  • void deleteFront() : The function deletes the first element of the list.
  • void deleteEnd() : The function deletes the last element of the list.
  • void deletePosition(int position) : The function deletes the element at the given position of the list. If the position < 1 or it is larger than the size of the list, only print ”outside range”.
  • int getItem(int position) : The function both prints the value of the item (followed by a space) and returns the value of the item at the given position of the list, If beyond the size of the array, both prints std::numeric_limits < int >::max() (followed by a space) and returns std::numeric_limits< int >::max(). You should include <limits> for this. Take a look at
    http://www.cplusplus.com/reference/limits/numeric_limits/ if you need.
  • void printItems() : The function prints the value of the items of the list from head to tail. In case of an empty list, it does not print anything
  • A constructor with no parameters, which makes an empty list.
  • A constructor that takes an array of integers and makes a linked list, containing all the elements of the array, in the same order. As the second parameter, it takes the size of the array.
  • A destructor that manually deletes all the elements that are still in the list.

Note that the printing in the functions search and getItem is for the purpose of easy testing.

Main function

The test script will compile your code using

g++ -o main.out -std=c++11 -O2 -Wall *.cpp

  

It is your responsibility to ensure that your code compiles on the university system. g++ has too many versions, so being able to compile on your laptop does not guarantee that it compiles on the university system. You are encouraged to debug your code on a lab computer (or use SSH).

You are asked to create a main function (main.cpp). It takes in one line of input.
  

int1 int2 ... intn FUNCTIONINITIAL param1 param2

int1, until intn are integers, separated by space, which should be placed in an integer array, and passed to the linked list constructor. For simplicity, we assume that the size of this array never exceeds 100; therefore, you can take an static array with the size of 100.

After the elements of the list, the input consists of an string, denoting a function, followed by its parameters. The string is one of these:

  • AF standing for addFront
  • AE standing for addEnd
  • AP standing for addAtPosition
  • S standing for search
  • DF standing for deleteFront
  • DE standing for deleteEnd
  • DP standing for deletePosition
  • GI standing for getItem

Call the indicated function with its parameter. If the function has only one parameter, then the last integer value from the input is not used. At the end, call the function printItems, to produce the required output.

  

Sample input: 5 2 7 10 AP 3 9

expected output: 5 2 9 7 10

Sample input: 3 4 2 1 DP 3 0

expected output: 3 4 1

Sample input: 45 20 2 10 GI 3 0

expected output: 2 45 20 2 10

In: Computer Science

Trace the following program. This means you need to fill the table in which you show...

Trace the following program. This means you need to fill the table in which you show the output of each executed instruction as if you are the computer executing the program. Put your comments under the table.

#include<iostream>

using namespace std;

int main ()

{

cout.setf(ios :: fixed);

cout.setf(ios :: showpoint);

cout.precision(2);

int A=7.5, B=2.5, C;                                                                                        //statement 1

double X,Y;

char Letter;

C = A/B;                                                                                                          //statement 2

X = 1.0*A/B;                                                                                                    //statement 3

if (C<X)

        Letter = 30*C;                                                                                         //statement 4

if (C=X)

        Letter = 20*C;                                                                                         //statement 5

if (C>X)

        Letter = 10*C;                                                                                         //statement 6

cout << "Letter = " << Letter+10 << endl;                                                       //statement 7

Letter = Letter + 10;                                                                                        //statement 8

cout << "Letter = " << Letter << endl;                                                             //statement 9

Y = 1.0*(A/B);                                                                                                 //statement 10

X = Y/ (B+5) + 2.5;                                                                                          //statement 11

cout.precision(1);

cout << "X = " << X << endl;                                                                           //statement 12

return 0;

}

In: Computer Science

Correct and complete this C++ program. You are not allowed to include a directory nor changing...

Correct and complete this C++ program. You are not allowed to include a directory nor changing a variable type or a loop syntax. Stick on the number of lines.

#include<iostream>

using namespace std;

int main ()

{

int N1, N2;

int power;

cout<<"Please enter N1 and N2 in order to calculate N1^N2. N1 should be a positive number. N2 should be between -9 and 9.\n";

cin>>N1>>N2;

while (…………..)

{

cout<<………………………………………….

cin>>………………………………………….

}

while (…………..)

{

cout<<………………………………………….

cin>>………………………………………….

}

……………………………………………..

if(power>0)

{

for(………… ; ………… ; …………)

………………………………………….

cout<<………………………………

}

else if(power<0)

{

for(………… ; ………… ; …………)

………………………………………….

cout<<………………………………

}

else

cout<<………………………………

return 0;

}

In: Computer Science

Write a C++ program to computer the nth Fibonacci Number in 3 ways. Clearly define which...

Write a C++ program to computer the nth Fibonacci Number in 3 ways. Clearly define which way you are solving in your code using comments. You must provide an algorithm to solve for the nth Fibonacci Number in 1. a straight-forward recursive solution 2. a top-down memoized solution and 3. a bottom-up dynamic programming solution. These algorithms will be tested with randomly generated input, and a single non-negative number will be given through command line.

In: Computer Science

JAVA (1) Create two files to submit: ItemToPurchase.java - Class definition ShoppingCartPrinter.java - Contains main() method...

JAVA

(1) Create two files to submit:

  • ItemToPurchase.java - Class definition
  • ShoppingCartPrinter.java - Contains main() method

Build the ItemToPurchase class with the following specifications:

  • Private fields
    • String itemName - Initialized in default constructor to "none"
    • int itemPrice - Initialized in default constructor to 0
    • int itemQuantity - Initialized in default constructor to 0
  • Default constructor
  • Public member methods (mutators & accessors)
    • setName() & getName() (2 pts)
    • setPrice() & getPrice() (2 pts)
    • setQuantity() & getQuantity() (2 pts)

(2) In main(), prompt the user for two items and create two objects of the ItemToPurchase class. Before prompting for the second item, call scnr.nextLine(); to allow the user to input a new string. (2 pts)

Ex:

Item 1
Enter the item name:
You entered: Chocolate_Chips

Enter the item price:
You entered: 3

Enter the item quantity:
You entered: 1



Item 2
Enter the item name:
You entered: Bottled_Water

Enter the item price:
You entered: 1

Enter the item quantity:
You entered:10


(3) Add the costs of the two items together and output the total cost. (2 pts)

Ex:

TOTAL COST
Chocolate_Chips 1 @ $3 = $3
Bottled_Water 10 @ $1 = $10

Total: $13

In: Computer Science

4. DNS hijacking is a common technique that is used by censors (i.e., networks who perform...

4. DNS hijacking is a common technique that is used by censors (i.e., networks who perform censoring actions), where fake DNS responses can be injected. As a DNS request could traverse a number of routers along the path, each router along the path could inject a fake DNS response. In the paper “The Collateral Damage of Internet Censorship by DNS Injection”, authors use a technique similar to traceroute to identify the router that actually injects the fake DNS response. Authors deliberately decrease the TTL (time-to-live) value in the IP header to monitor ICMP packet and fake DNS response to decide the router that injects fake response. In this paper, DNS is built on UDP. However, DNS can also be built on top of TCP. This expands the attack surface for attackers. Specifically, the censors inject RST packets to both the client and the server in one TCP connection if a DNS query in this connection carries “sensitive” information. Different from UDP, TCP requires three-way handshake. Therefore, the packet that carries sensative information (e.g., a TCP-based DNS query) will be the packet that comes later than packets for three-way handshake. Let us make the following assumptions for this question 1. We assume that DNS over TCP is using a publicly-known port number. 2. Censors are stateless, which means that they will not consider whether a TCP packet belongs to an established connection. They make decision based on each individual packet instead of packets belonging to the same connection. In order to make the method discussed in “The Collateral Damage of Internet Censorship by DNS Injection” to be useful in this new setting, we need to make a few changes of this method. Question: Please verify whether each of the following changes is needed or not (1 Point). And please justify your answer (1 Points). a. When you select a target IP to send honey queries, this IP should never respond you with TCP RST packets if you send a TCP-based DNS query to this IP. b. When you send out a honey query (a TCP-based DNS query with a sensitive domain) to a target IP, you can directly send this TCP-based DNS query to this target IP without establishing a TCP connection with the target IP (i.e., through 3-way handshake). c. You should now expect RST packets from the censor rather than a forged DNS response.

In: Computer Science

Problem Description: Game: Bean Machine or Galton Box To figure out if the ball falls to...

Problem Description: Game: Bean Machine or Galton Box

To figure out if the ball falls to Left or Right, you can generate a random number using Math.random(). If this random number is greater than or equal to 0.5 we assume the ball falls to the Right otherwise it falls to the Left (or vise versa).

If there are 8 slots, the ball should hit 7 nails (8 -1), thus you should run a loop 7 times to figure out the path for that ball. If you have N balls, this whole process should be repeated N times. Here is a basic algorithm.

# of balls = N

# of slots = K

array of K elements

for ( i = 0 to N) {

   int R = 0;

   for (j = 0 to K-1) {

        if ( random number >= 0.5)

                  R++;

}//end loop j

array[R] ++;

}// end loop i

Output the array to show how many balls are in each slot.

Things to DO!!!!!

Analysis: (3 points)

(Describe the problem including inputs and outputs in your own words.)

Design: (3 points)

(Describe the major steps in your algorithm for solving the problem.)

Coding: Write a well documented and properly indented Java source program. Your program should have a block comment with your name and a statement of purpose at the very top. Use meaningful variable names. You must have proper labels and informative statements for all inputs and outputs. (10 points)

Testing: (Describe how you test this program, you should use your own input data to test not just the test cases given in sample runs.) (4 points)

Test your program according to following test schedule and generate output to show the number of balls in each slot.

N K
10 8
50 10
100 20
500 30

What to Submit:

  1. A PDF with descriptions of Analysis, Design, and Testing. Must have a title with your name and assignment number. (Do not submit a Word document!!!!)
  2. Error free Java source program (Programs with syntax errors receive 0 credit) with methods, proper comments and indentation. Java source program is the program you wrote with .java file extension. (Do not submit a Word or any other document of your code!!!!)
  3. The Program outputs for the 4 different test cases in a PDF

In: Computer Science

one can tell by comparing nodes between two given trees whether they relate to each other,...

one can tell by comparing nodes between two given trees whether they relate to each other, by having a reflected symmetric structure (i.e. being mirror images of each other), having identical structure, or not being related at all. In this assignment, you are asked to implement the following features.
Hard-code some paired lists of integers.
Build binary search trees from each list
Print the binary search trees in the three orders discussed in class.
Determine if the two binary search trees are identical, mirrors of each other, or neither
Remove a number in each tree at random and compare the tree pair again

Further, since the methods of the binary search tree class have been presented with recursive function calls, it is now up to you to implement these recursive functions with iterative loops.

You must write a Class Node, a class TreeChecker and a class BinarySearchTree. For Java users, they must implement the following interfaces respectively:
public interface INode {

   //Getter of node data
   T getData();

   //Setter of node data
   void setData(T data);

    INode getLeftChild() ;

   void setLeftChild(INode leftChild) ;

   INode getRightChild() ;

   void setRightChild(INode rightChild);
  
}
public interface ITree {
   void setRoot(INode root);
INode getRoot();
void preorder();   // print tree in a preorder traversal
void inorder();   // print tree in an inorder traversal
void postorder();   // print tree in a postorder traversal
INode insert(INode root, T data); // insert data into tree
   INode remove(INode root, T data); //search/remove node with data
   T search(INode root, T data); //search and return data if it exists
   INode getMax(INode root); //return node with maximum value of subtree
   INode getMin(INode root); //return node with minimum value of subtree
}  
public interface ITreeChecker {
  
boolean isMirror(ITree root1, ITree root2); // check if two trees are mirror
// images
   boolean isSame(ITree root1, ITree root2); // check if two trees are identical
}

Then if you could run the code in this main class.

public class Main {

   public static void main(String[] args) throws IOException {  
       // build a tree for the following lists
// int array1[] = [4,1,9,12,3,2,8,7,16,20,13,11];
       // int array2[] = [4,1,9,12,3,2,8,7,16,20,13,11];

       //add more examples here

       Bst1 = new BinarySearchTree();
       Bst2 = new BinarySearchTree();
      
      
       //more trees for each example

       treeChecker = new TreeChecker();

       //build each BST

       //print each tree with each order of traversal

       //compare bst1 and bst2 as mirror images with tree checker
       If(treeChecker.isMirror(bst1, bst2))
           Print messages saying the trees are mirrors of each other
       // compare bst1 and bst2 as being identical with tree checker
       Else If(treeChecker.isSame(bst1, bst2))
           Print messages saying the trees are identical to each other
       Else
           Print message saying the trees are not related

       //randomly remove a number from each tree
       //compare bst1 and bst2 again

// more code here to finish regarding comparing the other BST pairs…
}

In: Computer Science

#include <stdlib.h> #include <stdio.h> #include <string.h> void clrScreen(int lines){     int i = 0;     for( i =...

#include <stdlib.h>

#include <stdio.h>

#include <string.h>

void clrScreen(int lines){

    int i = 0;

    for( i = 0; i < lines; ++i ){

        printf("\n");

    }

    return;

}

void printRules(void){

    printf("\t|*~*~*~*~*~*~*~*~*~ How to Play ~*~*~*~*~*~*~*~*~*~|\n");

    printf("\t|   This is a 2 player game. Player 1 enters the   |\n");

    printf("\t|   word player 2 has to guess. Player 2 gets a    |\n");

    printf("\t|   number of guesses equal to twice the number    |\n");

    printf("\t|   of characters. EX: If the word is 'example'    |\n");

    printf("\t|   player 2 gets 14 guesses.                      |\n");

    printf("\t|*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~|\n");

    clrScreen(10);

    return;

}

//------------------------------------------------------------------------------------------------------------

/* /\DO NOT MODIFY ABOVE THIS LINE /\*/

void playGame(){

int correctGuess = 1;

    char garbage;

clrScreen(40);

    printRules();

    printf("Player 1: Enter a word smaller than 50 characters: ");

    clrScreen(40);

    if( -1 == correctGuess ){

        printf("CoNgRaTuLaTiOnS!!!!!! You figured out the word!!!\n");

        printf("\t\t%s\n");

    } else {

        printf("You didn't figure out the word.....it was %s\n");

        printf("Better luck next time!\n");

    }

    printf("Press 'enter' to continue to main menu.\n");

    scanf("%c", &garbage);

}

int menu(void){

    int loop = 1;

    while( loop ){

        clrScreen(40);

        printf("*~*~*~*~*~*~*~*~*~*~Welcome to Hangman!*~*~*~*~*~*~*~*~*~*~\n");

        printf("\t1.) Play the game\n");

        printf("\t2.) Quit\n");

        printf("Please make a selection: ");

    }

}

/*

    hangman game RULES:

    2 player game

        player 1

            enter a word for player 2 to guess

            enter a number of guesses player 2 gets to have. It must be at least 2x as big

                as the number of letters in the word.

            For example, if you enter the word 'sky' you must give the player at least 6 guesses.

        player 2

            try to guess the word player 1 has entered.

            you get X number of guesses

*/

int main(void){

    return 0;

}

//In c programming language

//please help me finish this hangman program. Thank you.

In: Computer Science

PYTHON LANGUAGE PLEASE DO NUMBER 5 ONLY """ # 1. Based on Textbook R6.28 # Create...

PYTHON LANGUAGE

PLEASE DO NUMBER 5 ONLY

"""
# 1. Based on Textbook R6.28
# Create a table of m rows and n cols and initialize with 0
m = 3
n = 4

# The long way:
table = []
for row in range(m) :
table.append([0]*n)   

# The short way:

# 2. write a function to print the table in row, column format,
# then call the function
'''
# using index
def printTable(t):
for i in range(len(t)) : # each i is an index, i = 0,1,2
for j in range(len(t[i])) : # j = 0,1,2,3
print(t[i][j], end=' ')
print()
'''
# without index:
def printTable(t):
for row in t :
for col in row :
print(col, end=' ')
print()
print()

printTable(table)


# what does the following print?

for i in range(m):
for j in range(n):
table[i][j] = i + j

printTable(table)
'''
Answer:
print: from these index values:
0 1 2 3 [0,0] [0,1] [0,2] [0,3]
1 2 3 4 [1,0] [1,1] [1,2] [1,3]
2 3 4 5 [2,0] [2,1] [2,2] [2,3]
'''
  
# 3. copy table to table2
table2 = copy.deepcopy(table)

'''
table2 = table => table2 is another reference to the same mem location
table2 = table.copy() => shallow copy
only copy the 1D list (outer list) of references,
which has row1 - row4 references
table => [ row1 => [ , , , ]
row2 => [ , , , ]
row3 => [ , , , ]
row4 => [ , , , ]
]
'''
  
table[0][0] = -1 # will table2 be changed? No
printTable(table2)


# 4. fill elements of bottom row of table2 with -1's
# and all elements of left col of table2 with 0's

for i in range(len(table2[-1])) :
table2[-1][i] = -1
  
for i in range(len(table2)) :
table2[i][0] = 0
  
printTable(table2)
"""
"""
# 5. We start with a dictionary of student ids and associated gpa's
d = {123:3.7, 456:3.8, 789:2.7, 120:2.8}
print(d)

# create a list of sid list and a tuple of gpa from d

# create a list of tuples (k,v) from d

# How do you construct a dictionary from a list of tuples?


# How do you construct a dictionary from the list of id and gpa?


"""

In: Computer Science

Description Your program must start and keep dialog with the user. Please create the first prompt...

Description Your program must start and keep dialog with the user. Please create the first prompt for the dialog. After that your program must accept the user’s response and echo it (output to screen) in upper case and adding the question mark at the end. The program must run endlessly until the user say “stop” in any combination of cases. Then you program must say “GOODBYE!” and quit. Example: HELLO, I AM THE PROGRAM Hi, I am Michael HI, I AM MICHAEL? Are you kidding? ARE YOU KIDDING?? I prefer to speak to somebody smarter I PREFER TO SPEAK TO SOMEBODY SMARTER? Stupid STUPID? You YOU? sToP! STOP!? stop GOODBYE!

In: Computer Science

What is Stuxnet and what are its real-world implications? Should your national government be concerned about...

What is Stuxnet and what are its real-world implications? Should your national government be concerned about the potential of a Stuxnet-like attack? Why or why not.

In: Computer Science