CS 3377 Project

The goal: create several versions of a process that updates and saves a binary file as a new file.

The Setup

This project will be done in 4 parts. To keep them separate, I implemented a factory pattern so

that you (and the autograder) can test each copying method separately. It will look like this:

FileModifierFactory: creates

1. Part1SimpleFileModifier: fill in during part 1

2. Part2MultiProcessModifier: fill in during part 2

3. Part3ThreadedModifier: fill in during part 3

4. Part4SocketModifier: fill in during part 4

You will be given (and not need to modify):

1. main.cpp. Launches the appropriate test based on the arguments

2. Util.cpp/h. Includes some useful attributes.

3. FileModifierFactory.cpp & .h. These build the proper PartXModifier based on

the argument.

4. PipeCopier.cpp & .h. Helps you with the pipe for part 2.

While each part will be tested separately, you are encouraged to reuse code as much of it will

be useful for multiple parts.

The File

The file you are to read, modify, and save is a binary file that contains a sales list. A binary file is

a non-text file, meaning some things (like numbers) aren’t stored as digits but as the ints/floats

you use as variables. The name of the files to read and write will be in Util.h.

The file will be structured like this:

Field

Size

HEADER

NumEntries

4 bytes

Type Purpose

Integer Tells you how many

entries you need to

read

Timestamp (#

seconds since

1/1/1970)

Item’s code

Name of the item

sold

ENTRY (repeated

NumEntries times)

Date/Time sizeof(time_t) Time

Item ID

Item Name Sizeof(int)

50 bytes Integer

char*Item Quantity

Item Price

Sizeof(int)

Sizeof(float)

Integer

Float

Number sold

Price of the

products

What You’ll Do

In each part, the goal is to copy the file, adding two additional sales:

1. The Sobell book:

a. Time 1612195200 (2/1/2020 4 PM GMT)

b. ID 4636152

c. Name “A Programming Guide to Linux Commands, Editors, and Shell

Programming by Sobell” [warning: this is more than 49 characters, so you have

to truncate it—I say 49 because you need a null terminator]

d. Quantity: 70

e. Price: 70.99

2. The Advanced Programming book

a. Time 1613412000 (2/15/2020 6 PM GMT)

b. ID 6530927

c. Name “Advanced Programming in the UNIX Environment by Stevens and Rago”

[warning: more than 49 characters again]

d. Quantity: 68

e. Price: 89.99

Be sure to update the total number of entries to account for these new ones.

Part 1 (Due 3/29)

You will read in the file (Util::inputFileName), add the two entries, and save the file

(Util::outputFileName) using open(), close(), read(), and write().

You must use the low-level functions we will talk about in APUE chapter 3 (open, close, read,

write). Failure to do so will result in 0 points for this part of the project.

It is highly recommended that you do the file reading and writing in class(es) outside

Part1SimpleFileModifier, as that code will be useful later.

Part 2 (Due 4/12)

In this case you will spawn a new process using fork() and exec(), and split the responsibilities

like this:

1. The original process will read the file (2 nd argument=2) and then write the data over a

pipe to the child process.

2. The child process will read the file from the pipe (which will be set to standard input)

and write the data to the output file.

3. PipeMaker will take care of the pipe setup for you:a. Create PipeMaker before the fork.

b. In the parent process, call setUpToWrite() to ready this process for writing. You’ll

get back the file descriptor to write to. Write the file data to that file descriptor

(hint: it’s just like writing to a file).

c. In the child process, before execing, call setUpToRead() to dup the pipe output

to standard input. You can then exec the process (21S_CS3377_Project) with the

write option (2 nd argument=3), read the data from standard input (just a file

descriptor, remember!), and write to the output file.

d. Either the parent or the child process can do the update (but not both,

obviously).

When calling exec, use the command 21S_CS3377_Project 2 3. This will trigger main to

give you the proper setup for the child process. You will be responsible for spotting the

Util::IOType of WRITE (3), and read from standard input rather than the input file.

Part 3 (Due 4/26)

In this part you will create a thread and pass the file data from one thread to the other. The

threads will be like this:

1. Main thread: read the data, create the thread, and pass the data along

2. Created thread: receive the data and output it to the file

I did all of this inside of Part3ThreadedModifier. Create a mutex and condition for both threads

to share, and pass a pointer to the Part3ThreadedModifier object to pthread_create (and read

it in the other thread). Then you can use the shared mutex and condition to coordinate passing

the data.

The easiest way to pass the data is to use a variable inside Part3ThreadedModifier (type

EntryInfo). The main thread should lock the mutex before creating the receiving thread (and the

receiving thread should attempt to lock the mutex right after it starts up) to ensure the proper

ordering. Then do a loop in each thread like this:

Main (sending) thread

Wait on shared condition (for writing

thread to be ready)

Receiving thread

Signal condition to say we’re ready

Wait on condition (for an entry to be

ready)

Update the variable with the next entry

Signal the condition

Loop around and wait on the condition

again

Retrieve the info, save it for later writingLoop around and signal the condition

again

Once you’ve passed all the entries (5 or 7 depending on where you want to add the new ones),

unlock the mutex on both sides.

Part 4 (Due 5/10)

Here you will use two processes again, this time with a socket connecting them.

A port number to use (12345) is at Util::portNumber.

• Note: if you get an error that the port is already in use, it’s likely because you just ran

the project and the operating system hasn’t released the port yet. You can either wait a

bit (a few minutes at most) or change the port number (12346, etc.).

When I did this step, I reversed the setup from part 2: the main process here reads from the

socket (writing to the output file) and the spawned process writes to the socket (reading from

the input file). Again, it is up to you where you want to add the two new entries.

When you spawn the 2 nd process, use 21S_CS3377_Project 4 3.

After the fork, the socket reading process (parent process for me) creates a socket and listens

on that socket using the port number above. The socket writing process (child process for me)

creates a socket and connects to the listen socket. Depending on the timing of things the listen

socket may not be ready the first time; here is code to repeatedly wait for the listen socket to

be available:

int amountToWait = 1;

while ( connect(fileDescriptor, (struct sockaddr*) &serverAddress,

sizeof(serverAddress))) {

if ( errno != ECONNREFUSED) {

// Something unexpected happened

throw FileModifyException(“Error connecting”);

}

std::cout << "Not ready to connect yet...n";

// Exponential backoff

sleep(amountToWait);

amountToWait = amountToWait * 2;

}

Once the connection is made (reader gets back a file descriptor from accept() and the writer

gets out of the loop above) you can transfer the data. Remember that a socket is just a file

descriptor, so your code to write/read from earlier parts will work here, too.

Computer Science

  

1. Given a student registration system for the University of ABC. The university has Fall, Spring and Summer semesters for undergraduate and graduate classes. The student can register or drop any course before the deadline. Late registration and drop will be penalized by a certain amount of payment. Each undergraduate student can register at most 5 courses and minimum 3 courses. Each graduate student can register at most 3 courses and minimum 2 courses. All of the courses can be registered online. Each course has certain capacity (you can assume any number, e.g., 30). Your task is to model this simple registration system using correct Z notation. You need to define data, two operations (register and drop) and corresponding schemas. 

Note: Some Symbols that may be useful for this assignment: 

Power set: Ã

Change/update of database: D book

No update of database: Xbook

First Order Logic: 

Quantifiers: 

There is at least one element p in the set of patron: $ p Î patron. 

For all elements b in the set of book: ” b Î book.

Schema: 

      

Borrow-Success

  

D patron

 

{< “Prof.”, Yujian   Fu, 10111111, l, 0, l>,  … }

  

/* set   declaration is here */

 

/* constraints   are defined here */

X ¹ ∆ ” $ Î £ ³ Ù Ú

Linux2

 Answer the following questions (Don’t cut and paste answers form the book or the Internet):

  1. From the list of commonly used Linux commands shown, provide a functional description for each.  Expand the table to include 10 other Linux entries of your choice.

Linux Command    Function

cd 

ls 

mv 

man 

chmod 

traceroute 

ifconfig                      

  1. List at least six common distributions of Linux.  For example:  Debian, Ubuntu, etc.
  2. Provide a brief definition/discussion of the following command features:
    1. Backslash character
    2. Pipe
    3. Stat
    4. Netstat
    5. Jobs
    6. Sudo
    7. Chown
    8. Bang (“!”)
  3. Describe the use of ‘key combinations’ ( e.g. “CTRL-V” )and the use of the dash sign in-between the key which must be used in combination.

case study

  

In a 2-3 page APA formatted paper, describe your workplace taking an IT industry as an example

● Describe in detail the industry this company belongs to, and who represents its customer base. 

● Who is your customer in this organization, internal or external, and how do you serve your customers’ needs as an Intern/Employee? 

● Describe how your IT skills have helped you in your current job in terms of IT management and/or project management, leading a team, and enhancing your career in the field of IT management.

computer speeds

  • What is the significance of cache memory on computer performance? 
  • Explain how the principle of locality affects caching?
  • What does associativity mean in the context of caches?

watch videos below

  • https://youtu.be/p3q5zWCw8J4
  • https://youtu.be/rtAlC5J1U40

research paper need 800 – 1000 word review

Once you have finished reading the article, select a second article from the references in the first article or closely related to the topics in the first article and then write an 800 – 1000 word review of the two articles (combine the two reviews; do not write two separate reviews) in an R Markdown document. What are the main issues they address? How are the two article connected? List three things that you learned or three key take-aways (from either of the two papers). Are there statements that you do not agree with?

Please see the attached article 

regression using R

 

In the Zip File you’ll find three files. One called Assignment, one called reference, and one in CSV format called Global Ancestry.

Please follow the instructions in the assignment including all the notes. Also, For the reference, You can start at page 56 and from there everything else should hopefully make sense.

Requirements: Every Question answered]

https://drive.google.com/file/d/1VhTzVhcyhIbjmS9E4pJPxGHotAI9-VHw/view?usp=sharing

CPSC 131

  

Introduction 

CPSC 131 

Project 4 Requirements 

Representing and Evaluating Arithmetic Expressions 

We typically write arithmetic expressions with the operator placed in between its two operands.

For example, “2 + 3”; here, + is the operator and its two operands are 2 and 3. This notation is called Infix notation. The main disadvantage of infix notation is that the order of operations sometimes needs to be made clear with matching sets of parentheses. For example, “2 + 3 x 5” is different from “(2 + 3) x 5.” Therefore, computers represent arithmetic expressions using different notations where the order of operations is unambiguous without using additional symbols like parentheses.

In this project, you will implement two such representations, the Reverse Polish Notation and

Expression Trees and convert between representations. 

Expression Trees 

( Refer to Example 7.9 in page 285 of the textbook.) An arithmetic expression can be represented with a binary tree. For example, an expression of 3+5 can be represented by a binary tree shown below. 

Similarly, an expression of (3+5)*4 can be represented by 

A binary tree of an arithmetic expression can be constructed if we know its Reverse Polish notation (RPN). 

Reverse Polish Notation (RPN) 

RPN (also called postfix notation) is a mathematical notation in which every operator follows all of its operands. For example, the expression 3+5 can be rewritten as “3 5 +” and (3+5)*4 can be

rewritten as “3 5 + 4 *”. Visit https://en.wikipedia.org/wiki/Reverse_Polish_notation for more

information about Reverse Polish notation. 

Converting between representations 

Converting from Expression Tree to RPN 

Note that the postOrder traversal of an arithmetic binary tree gives the exact same expression as its Reverse Polish notation. 

Converting from RPN to Expression Tree 

Here, we use an example of “3 5 + 4*” to explain how to use RPN notation to construct a binary tree. First, create a stack that will contain nodes of a binary tree we are trying to build. Then, we parse the notation from left to right by steps: 

‘3’ is an operand. 

Create a node with it and push the node to stack (stack contains one node). 

‘5’ is an operand. 

Create a node with it and push the node to stack (stack contains two nodes).

‘+’ is an operator. 

Create a node with it, connect its left child and right child pointer with two nodes pop out of 

stack, and then push this node to stack (stack contains one node).

For every operator you parse in the expression, two operand nodes need to pop out of stack

since RPN requires that every operator follows all of its two operands.

’4’ is an operand

Create a node with it and push the node to stack (stack contains two nodes).

‘*’, is an operator. 

Create a node with it, connect its left child and right child pointer with two nodes pop out of 

stack, and then push this node to stack (stack contains one node)

Continue if there are more characters in expression.

The whole process can be simplified as a sequence of operations shown below. 

push(3)

push(5)

push((pop()+pop())

push(4)

push (pop() *pop())

At the end, there will be only one node in stack that is the root of this arithmetic binary tree. 

Converting from Expression Tree to Infix Notation 

An inorder traversal of an arithmetic binary tree where an open parentheses is output before

calling a left child and a close parentheses is output after returning from a right child gives a fully parenthesized infix expression. For example, the expression tree shown earlier results in “((3 + 5) *

4)”. Refer to Algorithm printExpression in page 303 of the textbook. 

Converting from Infix Notation to RPN 

Description of algorithm from 3.9.2. General Infix-to-Postfix Conversion, Problem Solving with

Algorithms and Data Structures using Python ; 

http://interactivepython.org/runestone/static/pythonds/BasicDS/InfixPrefixandPostfixExpressio

ns.html

Assume the infix expression is a string of tokens delimited by spaces. The operator tokens are *, /, +,

and -, along with the left and right parentheses, ( and ). The operand tokens are integers. The

following steps will produce a string of tokens in postfix order. 

1. Create an empty stack called opstack for keeping operators. Create an empty list for output.

2. Convert the input infix string to a list of tokens – operators, operands, or parentheses.

3. Scan the token list from left to right. 

If the token is an operand, add it to the end of the output list.

If the token is a left parenthesis, push it on the opstack.

If the token is a right parenthesis, pop the opstack until the corresponding left 

parenthesis is removed. Add each operator to the end of the output list.

If the token is an operator, *, /, +, or -, push it on the opstack. However, first remove 

any operators already on the opstack that have higher or equal precedence and add

them to the output list. 

4. When the input expression has been completely processed, check the opstack. Any

operators still on the stack can be removed and added to the end of the output list. 

Evaluating expressions 

Evaluating an expression is computing its final answer. It is much easier to evaluate expressions

represented in RPN or as Expression Trees than in infix notation. 

Evaluating expression trees 

The postorder traversal of an expression tree can be used to solve the evaluation problem. Refer to Evaluating an Arithmetic Expression in page 298 of the textbook for the algorithm. 

Evaluating RPN expressions 

A single stack is sufficient to evaluate an RPN expression.

Description of algorithm from 3.9.2. General Infix-to-Postfix Conversion, Problem Solving with

Algorithms and Data Structures using Python ; 

http://interactivepython.org/runestone/static/pythonds/BasicDS/InfixPrefixandPostfixExpressio

ns.html

Assume the postfix expression is a string of tokens delimited by spaces. The operators are *, /, +,

and -. The operands are assumed to be integers. The output will be an integer result (assuming

divison returns only the integer quotient). 

1. Create an empty stack called operandStack.

2. Scan the token list from left to right. 

If the token is an operand, convert it from a string to an integer and push the value

onto the operandStack. 

If the token is an operator, *, /, +, or -, it will need two operands. Pop the

operandStack twice. The first pop is the second operand and the second pop is the

first operand. Perform the arithmetic operation. Push the result back on the

operandStack. 

3. When the input expression has been completely processed, the result is on the stack. Pop

the operandStack and return the value. 

Objective 

You are to write a C++ program that will ask the user to enter an arithmetic expression in either infix or RPN. Your program should then return the expression in other notations (infix, RPN, and expression trees) and evaluate the expression into an integer. To do these, you will have to implement the algorithms

described above.

You are given the declarations of functions which will be called from main() to convert and evaluate expressions. Your are also given a class ArithNode which is to be used for nodes of a binary expression tree. 

You are to write the definitions of only the functions, adding other functions as needed. Your code is tested in the provided main.cpp . 

Simplifying assumptions 

There are only four binary operators: + – * /. The division operator returns the integer quotient.

Operands are positive integers.

There will be a space between every token – operators, operands, and parentheses.

There is no need for error checking (i.e., operators and operands will be as described above; 

parentheses will be matched).

The infix and RPN expressions will be input/output as strings. Expression trees will be 

represented as a pointer to the root node (* ArithNode ). The leaves of the expression trees

(operands) should have null left and right child pointers (not empty “external” nodes). 

You are given the code to “print” an expression tree in main.cpp. You just need to construct the tree. 

● There are multiple ways to implement some of the functions. For example, to evaluate an infix

expression, you can convert to RPN and evaluate the RPN expression, or convert to an expression tree and evaluate the tree. You only need to implement one method (your choice). 

● Note that since each function is a stand-alone function, they are not made part of a class.

● You will need to use other data structures, especially a stack. It is recommended that you use the  C++ Standard Library containers (std::stack). 

Source Code Files 

The starter C++ code has multiple files:

● ExpressionConverter.h : This contains the declarations of the functions to be 

implemented. This also contains the class ArithNode. This file is already complete and you

should not change this code. 

● ExpressionConverter.cpp : This is to be completed with definitions of the functions

which will be called from main(). You can add other functions as needed. 

● main.cpp : Code that brings everything together into one application. The main function also

tests the output of your functions. This is already complete and you should not change this code. 

● A README.md file. You must edit this file to include the name and CSUF email address of each student in your group as in other projects. 

Obtaining and submitting code 

We will again be using GitHub Classroom to distribute starter code. The assignment link is:

https://classroom.github.com/g/8r6pk2xh 

When you choose a team name make sure it begins with your section number (1, 2, 3, 4,

5, 6, or 8). Example: 2-myteamname