Questions
Write a bash script file that tests each file entry in the current directory. It should...

Write a bash script file that tests each file entry in the current directory. It should determine if it is a file or directory. If it is a file, it will determine if it is readable or not. If it is readable, it will display only the first 4 lines to the terminal in sorted order (just sort the first 4 lines).
If it is a directory, it should display the contents of that directory (the files and subdirectories).
NOTE: Please don’t use the read command or arguments with your script. Note that you don’t need to use either one of these methods to get a list of files in the current directory.
=====================================
Example Output
Note that the output
from running the script starts at
the sixth line
=====================================
$ ls -l
total 32
drwxrwxr-x 3 cocofan cocofan 4096 Jan 20 17:58 adir
--w-rw-rw- 1 cocofan cocofan 128 Mar 15 22:43 lines.dat
-rw-rw-rw- 1 cocofan cocofan 48 Sep 5 2016 months.txt
$ bash assg5.sh
ENTRY IS adir
**This is a directory**
afileinadir.txt subdirofadir
ENTRY IS lines.dat
**This is a file**
...file is not readable.
ENTRY IS months.txt
**This is a file**
...and it's readable.
...it's first four lines in sorted order are:
Apr
Feb
Jan
Mar
$
++++++++++++++++++++++++++++++++++++

In: Computer Science

Having a difficult time writing this code up. ( JAVA based ) Will Copy and paste...

Having a difficult time writing this code up. ( JAVA based ) Will Copy and paste the whole solution I was left with. Thank you in advance !

Lab 5 – Class Statistics

Write a program which will uses the file Lab5Data.txt containing student names and the points they had earned at the end of the class. The program should use one or more arrays to create a report with the following information:

-A table containing the student name, total points they earned and the letter grade that would be given.

-The student with the highest score and the average points earned and average letter grade given

You may use single single dimension arrays, multi-dimension arrays or both.

Capture screen output of your report and save as GradeReport.txt

(Optionally, you may add code to create this file using java; see note below)

Name your program Grade.java. Upload files Grade.java, and GradeReport.txt to Canvas.

Note: the data files mentioned downloaded from the Canvas files area.

Refer to the files TipsForLab5.pdf, ReadData.txt, WriteData.txt for additional information that may be usefull in completing this lab.

In: Computer Science

ANSWER WITH ML CODE PLZ. NOT C++ 1) fun main() = let val yy = [6,4,2,0];...

ANSWER WITH ML CODE PLZ. NOT C++

1)

fun main() = let
val yy = [6,4,2,0];
in print (PolyML.makestring (

***(Remove the first item from yy)******

)) end;

2)

fun main() = let
val yy = [6,4,2,0];
in print (PolyML.makestring (

***(Make a list containing only the first item of yy )***

)) end;

3)

fun main() = let
val yy = [8,6,4,2,0];
in print (PolyML.makestring (

***(Prepend 5 to the front of yy)***

)) end;

4)fun main() = let
val yy = [8,6,4];
in print (PolyML.makestring (

***(Prepend [2,5] to the front of yy )***

)) end;

5) fun main() = let
val yy = [8,6,4,2];
in print (PolyML.makestring (

***(Remove the third integer from yy )***

)) end;

In: Computer Science

Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is...

Programming Language: C#

CheckingAccount class

You will implement the CheckingAccount Class in Visual Studio. This is a sub class is derived from the Account class and implements the ITransaction interface. There are two class variables i.e. variables that are shared but all the objects of this class. A short description of the class members is given below:

CheckingAccount

Class

Fields

$- COST_PER_TRANSACTION = 0.05 : double

$- INTEREST_RATE = 0.005 : double

- hasOverdraft: bool

Methods

+ «Constructor» CheckingAccount(balance = 0 : double, hasOverdraft = false: bool)

+ Deposit(amount : double, person : Person) : void

+ Withdraw(amount : double, person : Person) : void

+ PrepareMonthlyReport(amount : double, person : Person) : void

Fields:

  1. COST_PER_TRANSACTION – this is a class variable of type double representing the unit cost per transaction. All of the objects on this class will have the same value. This class variable is initialized to 0.05.
  2. INTEREST_RATE – this is a class variable of type double representing the annual interest rate. All of the objects on this class will have the same value. This class variable is initialized to 0.005.
  3. hasOverdraft – this is a bool indicating if the balance on this account can be less than zero. This private instance variable is set in the constructor.

Methods:

  1. public CheckingAccount( double balance = 0, bool hasOverdraft = false ) – This public constructor takes a parameter of type double representing the starting balance of the account and a bool indicating if this account has over draft permission. The constructor does the following:
    1. It invokes the base constructor with the string “CK-” and the appropriate argument.
    2. Assigns the hasOverdraft argument to the appropriate field.
  2. This definition hides the corresponding member in the parent class because the base class implementation is needed for this method as well as the Withdraw() method

    public new void Deposit( double amount, Person person ) – this public method takes two arguments: a double representing the amount to be deposited and a person object representing the person do the transaction. The method does the following:
    1. Calls the Deposit() method of the base class with the appropriate arguments
  3. public void Withdraw( double amount, Person person ) – this public method takes two arguments: a double representing the amount to be withdrawn and a person object representing the person do the transaction. The method does the following:
    1. Throws an AccountException object if this person in not associated with this account.
    2. Throws an AccountException object if this person in not logged in.
    3. Throws an AccountException object if the withdrawal amount is greater than the balance and there is no overdraft facility.
    4. Otherwise it calls the Deposit() method of the base class with the appropriate arguments (you will send negative of the amount)
  4. public override void PrepareMonthlyReport( ) – this public method override the method of the base class with the same name. The method does the following:
    1. Calculate the service charge by multiplying the number of transactions by the COST_PER_TRANSACTION (how can you find out the number of transactions?)
    2. Calculate the interest by multiplying the LowestBalance by the INTEREST_RATE and then dividing by 12
    3. Update the Balance by adding the interest and subtracting the service charge
    4. In a real-world application, the transaction objects would be archived before clearing.

      transactions is re-initialized (use the Clear() method of the list class)

This method does not take any parameter nor does it display anything

SavingAccount class

You will implement the SavingAccount Class in Visual Studio. This is a sub class derived from the Account class and implements the ITransaction interface. Again, there are two class variables. A short description of the class members is given below:

SavingAccount

Class

→ Account, ITransaction

Fields

$- COST_PER_TRANSACTION : double

$- INTEREST_RATE : double

Methods

+ «Constructor» SavingAccount(balance = 0 : double)

+ Deposit(amount : double, person : Person) : void

+ Withdraw(amount : double, person : Person) : void

+ PrepareMonthlyReport(amount : double, person : Person) : void

Fields:

  1. COST_PER_TRANSACTION – this is a class variable of type double representing the unit cost per transaction. All of the objects on this class will have the same value. This class variable is initialized to 0.05.
  2. INTEREST_RATE – this is a class variable of type double representing the annual interest rate. All of the objects on this class will have the same value. This class variable is initialized to 0.015.

Methods:

  1. public SavingAccount( double balance = 0 ) – This public constructor takes a parameter of type double representing the starting balance of the account. The constructor does the following:
    1. It invokes the base constructor with the string “SV-” and its argument.
  2. public new void Deposit( double amount, Person person ) – this public method takes two arguments: a double representing the amount to be deposited and a person object representing the person do the transaction. The method calls the Deposit() method of the base class with the appropriate arguments.
  3. public void Withdraw( double amount, Person person ) – this public method takes two arguments: a double representing the amount to be withdrawn and a person object representing the person do the transaction. The method does the following:
    1. Throws an AccountException object if this person in not associated with this account.
    2. Throws an AccountException object if this person in not logged in.
    3. Throws an AccountException object if the intended withdrawal amount exceeds the balance.
    4. Otherwise it calls the Deposit() method of the base class with the appropriate arguments (you will send negative of the amount)
  4. public override void PrepareMonthlyReport( ) – this public method override the method of the base class with the same name. The method does the following:
    1. Calculate the service charge by multiplying the number of transactions by the COST_PER_TRANSACTION (how can you find out the number of transactions?)
    2. Calculate the interest by multiplying the LowestBalance by the INTEREST_RATE and then dividing by 12
    3. Update the Balance by adding the interest and subtracting the service charge
    4. transactions is re-initialized (use the Clear() method of the list class)

This method does not take any parameters, nor does it display anything

In: Computer Science

C++ Data Structures 4. Write a client function that merges two instances of the Sorted List...

C++ Data Structures

4. Write a client function that merges two instances of the Sorted List ADT using the following specification.

MergeLists(SortedType list1, SortedType list2, SortedType& result)

Function: Merge two sorted lists into a third sorted list.

Preconditions: list1 and list2 have been initialized and are sorted by key using function ComparedTo.

list1 and list2 do not have any keys in common.

Postconditions: result is a sorted list that contains all of the items from list1 and list2.

c. Write the function definition, using a linked implementation.

In order to verify that the code of MergeLists(SortedType list1, SortedType list2, SortedType& result) works, please integrate your code in the SortedType code below

**Use a driver to test your code.

//ItemType.h

#include <fstream>
const int MAX_ITEMS = 5;
enum RelationType {LESS, GREATER, EQUAL};

class ItemType
{
public:
ItemType();
RelationType ComparedTo(ItemType) const;
void Print(std::ostream&) const;
void Initialize(int number);
private:
int value;
};

#include "ItemType.h"
// Header file for Sorted List ADT.
struct NodeType;

class SortedType
{
public:
SortedType(); // Class constructor  
~SortedType(); // Class destructor

bool IsFull() const;
int GetLength() const;
void MakeEmpty();
ItemType GetItem(ItemType& item, bool& found);
void PutItem(ItemType item);
void DeleteItem(ItemType item);
void ResetList();
ItemType GetNextItem();

private:
NodeType* listData;
int length;
NodeType* currentPos;
};

struct NodeType
{
ItemType info;
NodeType* next;
};

SortedType::SortedType() // Class constructor
{
length = 0;
listData = NULL;
}

bool SortedType::IsFull() const
{
NodeType* location;
try
{
location = new NodeType;
delete location;
return false;
}
catch(std::bad_alloc exception)
{
return true;
}
}

int SortedType::GetLength() const
{
return length;
}

void SortedType::MakeEmpty()
{
NodeType* tempPtr;

while (listData != NULL)
{
tempPtr = listData;
listData = listData->next;
delete tempPtr;
}
length = 0;
}

ItemType SortedType::GetItem(ItemType& item, bool& found)
{
bool moreToSearch;
NodeType* location;

location = listData;
found = false;
moreToSearch = (location != NULL);

while (moreToSearch && !found)
{
switch(item.ComparedTo(location->info))
{
case GREATER: location = location->next;
moreToSearch = (location != NULL);
break;
case EQUAL: found = true;
item = location->info;
break;
case LESS: moreToSearch = false;
break;
}
}
return item;
}

void SortedType::PutItem(ItemType item)
{
NodeType* newNode;     // pointer to node being inserted
NodeType* predLoc;     // trailing pointer
NodeType* location;    // traveling pointer
bool moreToSearch;

location = listData;
predLoc = NULL;
moreToSearch = (location != NULL);

// Find insertion point.
while (moreToSearch)
{
switch(item.ComparedTo(location->info))
{
case GREATER: predLoc = location;
   location = location->next;
moreToSearch = (location != NULL);
break;
case LESS: moreToSearch = false;
break;
}
  
}

// Prepare node for insertion
newNode = new NodeType;
newNode->info = item;
// Insert node into list.
if (predLoc == NULL) // Insert as first
{
newNode->next = listData;
listData = newNode;
}
else
{
newNode->next = location;
predLoc->next = newNode;
}
length++;
}
void SortedType::DeleteItem(ItemType item)
{
NodeType* location = listData;
NodeType* tempLocation;

// Locate node to be deleted.
if (item.ComparedTo(listData->info) == EQUAL)
{
tempLocation = location;
listData = listData->next;   // Delete first node.
}
else
{
while (item.ComparedTo((location->next)->info) != EQUAL)
location = location->next;

// Delete node at location->next
tempLocation = location->next;
location->next = (location->next)->next;
}
delete tempLocation;
length--;
}

void SortedType::ResetList()
{
currentPos = NULL;
}

ItemType SortedType::GetNextItem()
{
ItemType item;
if (currentPos == NULL)
currentPos = listData;
item = currentPos->info;
currentPos = currentPos->next;
return item;

}

SortedType::~SortedType()
{
NodeType* tempPtr;

while (listData != NULL)
{
tempPtr = listData;
listData = listData->next;
delete tempPtr;
}

}

In: Computer Science

Implement a class named stack pair that provides a pair of stacks. Make the class a...

Implement a class named stack pair that provides a pair of stacks. Make the class a template class. So, you will have two files: stack pair.h and stack pair.template, following the style of the text. The basic idea is that two stacks can share a single static array. This may be advantageous if only one of the stacks will be in heavy use at any one time.

• The class should have various methods to manipulate the stack:

T pop a()

T pop b()

These methods pop the top of the respective stack and return the value. Use assert to cause the program to fail if an attempt is made to pop from an empty list.

• void push a(T item)

void push b(T item)

These methods push the value onto the respective stack. Use assert to cause the program to fail if an attempt is made to push to a full stack.

• size t size a()

size t size b()

These methods return the size of the respective stack. 1

• bool is empty a()

bool is empty b()

These methods return true if the respective stack is empty and return false if the stack is not empty.

• is full a()

is full b()

These methods return true if the respective stack has no more space for new data to be pushed.

The methods return false if the respective stack has space available. Because of the implementation, these two methods will always return the same thing. The implementation of the stack should be done with a single static array. Define the CAPACITY of that array as a static constant of size 30, to start with. Variables will be needed to keep track of the top of each stack, we’ll call them top a and top b. For illustrations, we’ll use the following diagram. The CAPACITY is only 16. Notice that top a and top b indicate where the next element will go when pushing.

Test your work by writing four programs. Two of these will be copies of others. When you are instructed to check something, use an if-statement and, if the expected behavior fails, print a message and terminate the program using the exit function. Write a program that will push a few values onto the a stack, then push a few values onto the b stack. The program should pop the values on the a stack and check that they are correct as they are popped. The program should pop the values on the b stack and check that they are correct as they are popped. Copy the previous program and increase the number of values pushed on a and or b to get a total number of CAPACITY values pushed between the two stacks. The program should not fail and both stack-full functions should return true. Copy the previous program and push one more value onto one of the stacks. The program should fail. Write a program that will check that popping from an empty stack terminates the program.

In: Computer Science

ok here is my homework This assignment focuses on file streams. Your program will accept the...

ok here is my homework

This assignment focuses on file streams.

Your program will accept the name of an input file from the user, and the name of an output file from the user. You may assume the input file contains no more than 100 lines.

Your program will write the lines of the input file to the output file in reverse line order, i.e. the first line of the input file becomes the last line of the output file, the second line of the input file becomes the second-to-the-last line of the output file, and so forth. Note that the lines themselves are not reversed, only the order in which the lines appear.

In: Computer Science

1.What are the four components of a process? What is the term that describes saving the...

1.What are the four components of a process? What is the term that describes saving the state of one process, and restoring the state of another?

2.Draw and Explain function of Process Control Block(PCB).

3.      Explain 5 State process model, how it differ from 3 state Model. Which model is better, justify your answer

In: Computer Science

Write a MATLAB function that calculates the approximate value of arctan(x) using the Maclaurin series approximation:...

Write a MATLAB function that calculates the approximate value of arctan(x) using the Maclaurin series approximation: arctan⁡(x)=x-x^3/3+x^5/5-x^7/7+⋯ The function should accept 3 parameters: value of x, number of significant figures accuracy i.e. n, and the maximum number of iterations. In the function, use ε_s=(0.5×〖10〗^(2-n ) )% in order to continue until the ε_a falls below this criteria. The function should return 3 values: the approximate value of arctan(x) at the end of the program, final ε_a and the number of iterations it took.

In: Computer Science

Design a simple database to track people and who they voted for. The database should have...

Design a simple database to track people and who they voted for. The database should have 3 tables:

A table of candidates
A table of registered voters
A table of votes
The candidate table should provide a listing of all candidates and information about the candidates.
The registered voter table should hold all registered voters and any pertinent information about them
The vote table should hold vote records for each candidate made by the voters

Requirements:

The system should not allow duplicate voters to be added to the registered voter table based on a voter_id number field
The system should reject duplicate votes by the same voter
Pick the relevant fields needed for each table to make the system useful
Provide:

SQL code to create the three tables
SQL code to insert test data into the database
A SQL query to retrieve the vote of record of a particular individual

In: Computer Science

Explain the role of slow start and congestion avoidance in TCP.

Explain the role of slow start and congestion avoidance in TCP.

In: Computer Science

In assignment 1 you had used the data structure called Stack to evaluate arithmetic expressions by...

In assignment 1 you had used the data structure called Stack to evaluate arithmetic expressions by first converting the given infixed expressions to postfixed expressions, and then evaluated the post fixed expression.

Repeat the exercise for this assignment (assignment 2) by using the data structure called Binary Trees. Your output must display the original expression, the postfixed expression representing the Binary tree, and the evaluated result.

Please bear in mind that a given expression could result in one of the following:

• Mismatch parentheses

• Too many operators, or too many operands in which case the expression would not have been written properly in the first place

• The result is assumed to be correct.

previous assigment :

import java.util.*;
class Arithmetic{
    public String exp,postfixexp;
    public Arithmetic(String exp){
        this.exp=exp;
        this.postfixexp="";
    }
    //___________________________isBalance()__________________
    public boolean isBalance(){
        Stack<Integer> stk = new Stack<Integer>();
        int i;
        for(i=0;i<exp.length();i++){
            char ch=exp.charAt(i);
            if(ch=='('){
                stk.push(i);
            }
            else if(ch==')'){
                if(!stk.isEmpty()){
                    stk.pop();
                }   
                else{
                    return false;
                }
            }
        }
        if(stk.isEmpty()){
            return true;
        }
        else{ 
            return false;
        }
    }
    //__________________________postFixExpression()_______________
    public int Prec(char ch) 
    { 
        switch (ch) 
        { 
        case '+': 
        case '-': 
            return 1; 
       
        case '*': 
        case '/': 
            return 2; 
       
        case '^': 
            return 3; 
        } 
        return -1; 
    } 
    public void postFixExpression() 
    { 
        Stack<Character> stack = new Stack<>(); 
        for (int i = 0; i<exp.length(); ++i) 
        { 
            char c = exp.charAt(i); 
            if (Character.isLetterOrDigit(c)) 
                postfixexp += c; 
            else if (c == '(') 
                stack.push(c); 
            else if (c == ')') 
            { 
                while (!stack.isEmpty() && stack.peek() != '(') 
                    postfixexp += stack.pop(); 
                    stack.pop(); 
            } 
            else
            { 
                while (!stack.isEmpty() && Prec(c) <= Prec(stack.peek())){ 
                    postfixexp += stack.pop(); 
             } 
                stack.push(c); 
            } 
       
        } 
        while (!stack.isEmpty()){ 
            postfixexp += stack.pop(); 
         } 
    }
    public String getPostfix(){
        return postfixexp;
    }
    //______________________evaluateRPN_____________________
    public float evaluateRPN() 
    {
        Stack<Float> stack=new Stack<>(); 
        for(int i=0;i<postfixexp.length();i++) 
        { 
            char c=postfixexp.charAt(i); 
            if(Character.isDigit(c)) 
            stack.push((float)c - '0'); 
            else
            { 
                float val1 = stack.pop(); 
                float val2 = stack.pop(); 
                  
                switch(c) 
                { 
                    case '+': 
                    stack.push(val2+val1); 
                    break; 
                      
                    case '-': 
                    stack.push(val2- val1); 
                    break; 
                      
                    case '/': 
                    stack.push(val2/val1); 
                    break; 
                      
                    case '*': 
                    stack.push(val2*val1); 
                    break; 
              } 
            } 
        } 
        return stack.pop();     
    } 
    
}

In: Computer Science

Developing a Faster Intersection Algorithm Scenario We have already seen an algorithm that produces an intersection...

Developing a Faster Intersection Algorithm Scenario We have already seen an algorithm that produces an intersection between two input arrays in Snippet 1.6, shown below:

public List intersection(int[] a, int[] b) {

List result = new ArrayList<>(a.length);

for(int x : a) {

for(int y : b) {

if (x == y) result.add(x);

}

}

return result;

}

We have already shown how the runtime complexity of this algorithm is O(n2). Can we write an algorithm with a faster runtime complexity?

To find a solution for this problem, think about how you would you go about finding the intersection by hand between two decks of playing cards. Imagine you take a subset from each shuffled deck; which technique would you use to find the common cards between the first and second deck?

Aim

Improve the performance of the array intersection algorithm and reduce its runtime complexity.

Prerequisites

You will find two methods for improving the intersection: The slow intersection:

public List intersection(int[] a, int[] b)

The empty stub, returning null: public List intersectionFast(int[] a, int[] b)

Use the second, empty stub method, to implement a faster alternative for the intersection algorithm.

Assume that each array has no duplicate values.

Steps for Completion

Assume that we have a way to sort the inputs in O(n log n). This is provided in the following method:

public void mergeSort(int[] input) {

Arrays.sort(input);

}

We can use this method to sort one input array, or both, and make the intersection easier.

To sort one input array, we can use a binary search on it. The runtime complexity is O(n log n) for the merge sort plus O(n log n) for the binary search per item in the first list. This is nlog+ nlog n which results in a final O(n log n).

Sort both arrays, and have two pointers, one for each array.

Go through the input arrays in a linear fashion. Advance a pointer if the other pointer is pointing to a larger value.

If the values at both pointers are equal, both pointers are incremented. The runtime complexity for this algorithm is 2 (n log n) for the two merge sorts plus the n for the linear pass after the sorting. This results in 2 (n log n) + n with a final O(n log n).

CODE TO WORK WITH:

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class SimpleIntersection {

private BinarySearch search = new BinarySearch();

public List<Integer> intersection(int[] a, int[] b) {
List<Integer> result = new LinkedList<>();
for (int x : a) {
for (int y : b) {
if (x == y) result.add(x);
}
}
return result;
}

public List<Integer> intersectionFast(int[] a, int[] b) {
// Write your code here
return null;
}

public void mergeSort(int[] input) {
Arrays.sort(input);
}

public static void main(String[] args) {
Intersection inter = new Intersection();
System.out.println(inter.intersection(new int[]{4, 7, 5, 2, 3}, new int[]{4, 2, 3, 9, 1}));
System.out.println(inter.intersection(new int[]{4, 6, 11, 2, 3}, new int[]{5, 11, 3, 9, 1}));

// Write your code here

}
}

In: Computer Science

In Reinforcement Learning, Is it possible for the agent to rely on the state value-based learning...

In Reinforcement Learning, Is it possible for the agent to rely on the state value-based learning approach to achieve its goal?

In: Computer Science

In C++, use SML programs to accomplish each of the following tasks: a) Use a sentinel-controlled...

In C++, use SML programs to accomplish each of the following tasks:

a) Use a sentinel-controlled loop to read positive numbers and compute and display their sum. Terminate input when a negative number is entered.

b) Use a counter-controlled loop to read seven numbers, some positive and some negative, and compute and display their average.

c) Read a series of numbers, and determine and display the largest number. The first number read indicates how many numbers should be processed.

For input you should read the instructions from a file (after prompting the user for the name of the file to read). Make the intro banner say "Welcome to Simpletron! Enter the name of the file containing your program:"

Here is a sample of the output expected:

Execution halted normally

REGISTERS:

accumulator -1

instructionCounter 6

instructionRegister 4300

opcode 43

operand 0

MEMORY:

0 1 2 3 4 5 6 7 8 9

0 1007 1008 2007 3008 2109 1109 4300 4 -5 -1

10 0 0 0 0 0 0 0 0 0 0

. . .

90 0 0 0 0 0 0 0 0 0 0

Please show the output files for a, b, and c. Thank you.

In: Computer Science