• Learning Tips
  • Exam Guides
  • School Life

Assignment 4 String Shortener Algorithm 2: How to Prepare

  • by Joseph Kenas
  • May 10, 2023

Prepare and Pass Assignment 4

In this assignment, you will be asked to prepare a string shortener algorithm. This means you will have to define and implement a solution that can do the job. 

You will have to work with some data structures and algorithms and with at least one programming language. 

The main goal of this part is to show that, nowadays, some algorithms can get implemented with very little computational resources.

What is the Assignment 4 String Shortener?

Assignment 4 String Shortener is a manipulation tool that can shorten any string. It is a very simple and easy-to-use application that you can use for your personal or professional needs.

shortening algorithm

It has been designed with a clear interface so that you can easily understand its functionalities.

The data analysis section of the program allows you to perform calculations on the shortened strings before applying them to other applications.

This feature provides an easy way of testing different combinations of characters before sending them to other programs.

Each part of the program has been carefully designed to make it easy for users to understand how each part works without having to read any documentation.

The program has been built using C++, which makes it very fast and efficient. The user interface consists of three buttons: “Add”, “Clear”, and “Save”, which are located at the bottom right corner of the window.

This design helps users navigate through all its features easily without looking at documentation or tutorials beforehand.

How to Prepare for your String Shortener Algorithm 2 Assignment 4

The first step in preparing for your string shortener algorithm two assignment 4 is ensuring you have the right software. You will be at a disadvantage if you don’t have the right tools.

be prepared

The second step is to find out what kind of data you will be working with.

You need to know exactly what type of information will be processed by your program and how it will be processed.

In this case, for example, we can use a spreadsheet containing information about restaurants, their location and menu items.

The third step is to gather as much information about the restaurant business as possible, including its financial data and records from previous years.

This will help us analyze how fast or slow restaurants are growing over time and how much money they spend on advertising each month.

After all these preparations have been made, our next step is to write down all the rules we will need for our algorithm to identify all possible shortcuts in our calculations later on.

Finally, we create an outline describing how each rule should work so that it’s easier for us to understand and remember them when implementing them into our code later on.

How to Pass Your String Shortener Assignments/exams

There are many ways to pass your string shortener exams and others like assignment 6 animations . The most important thing is to study hard and not give up.

The following tips will help you in the process of passing your string shortener assignments.

preparing for assignments

  • Read the instructions for each assignment or exam carefully;
  • Understand the problem
  • Before writing any code, understand the problem you are solving.
  • This will help you write efficient code and make it more readable.
  • Always be prepared for the test by having all the materials and notes;
  • Get enough sleep for a good night’s rest;
  • Don’t procrastinate, but start working on your assignment/exam as soon as possible.
  • Take breaks when necessary, but don’t stop working too early.

Tips on How to Learn Coding Fast

This is the time to take your first steps in learning to code. You have to start somewhere, so let’s make it easy. Here are some tips that will help you learn to code fast:

1. Learn Coding Basics

Learning the basics of coding is the first step toward becoming a good coder. This includes knowing what different programming languages are and how they work.

Understanding the underlying programming concepts is important because it helps you understand how things work in real life. 

You can start by learning basic concepts like variables, functions, loops and conditions. These lessons will teach you about the fundamentals of programming and how they work together to create programs that run on computers.

2. Study Online Courses

learn coding

Suppose you want to learn to code fast.

In that case, you should consider taking online courses instead of enrolling in an actual university program or college course.

This is because they’re much more convenient and flexible than traditional education programs (and also much cheaper).

Many free online courses teach basic programming skills such as HTML, JavaScript and CSS (Cascading Style Sheets).

These courses are perfect if you want to learn to program but don’t have computer access at home or elsewhere around town. 

3. Read code

It’s impossible to understand how something works without seeing it in practice — and reading other people’s code is one of the best ways to do this.

Try looking at different people’s implementations of common tasks like string manipulation and object instantiation.

 More importantly, these sorts of things are often very similar between languages, so it will be easier to learn how something works if you see how someone else has done it first.

4. Never Stop Learning

don't stop learning

Another thing that you should do is never stop learning. You should always look for new ways to improve yourself as a programmer.

If no new technologies were being created today, then your job as a software developer would be much harder than it is now.

The world of technology has changed rapidly over the last decade, and it will only get faster with time.

5. Keep up With the Latest Trends

Keeping up with the latest trends in a programming language can help you learn new things quickly because they are constantly changing and evolving every day.

You must not fall behind when it comes to these trends because they will help you stay ahead of everyone else who isn’t as passionate about learning to program as you are!

string shortener assignment 4

Joseph is a freelance journalist and a part-time writer with a particular interest in the gig economy. He writes about schooling, college life, and changing trends in education. When not writing, Joseph is hiking or playing chess.

Search code, repositories, users, issues, pull requests...

Provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications

Assignment 4

The goal of this assignment is to work with files, iterators, strings, and string formatting in Python.

Instructions

You will be doing your work in a Jupyter notebook for this assignment. You may choose to work on this assignment on a hosted environment (e.g.  tiger ) or on your own local installation of Jupyter and Python. You should use Python 3.12 for your work although earlier versions should also work. To use tiger, use the credentials you received. If you work remotely, make sure to download the .ipynb file to turn in. If you choose to work locally, Anaconda or miniforge are probably the easiest ways to install and manage Python. If you work locally, you may launch Jupyter Lab either from the Navigator application or via the command-line as jupyter lab .

In this assignment, we will be working with data from U.S. Department of Agriculture’s Economic Research Service about weekly food sales in 43 states (others are not available due to how the data is collected) made available during the COVID-19 pandemic. I have downloaded and pre-processed the data here , converting it to a fixed-width file format written using the UTF-16 encoding. There are five fields, whose locations ( inclusive ) in each line are as follows:

  • State : (0-13) the name of the state ( contains spaces )
  • Date : (16-25) the end of the week of the data collection in yyyy-mm-dd format
  • Category : (28-54) the food category ( contains spaces )
  • Dollars : (57-65) the total value of sales
  • LastYear : (68-76) the total value of sales last year (can be -999 which indicates no data is available)

The indices not included in a range are filled with spaces; for example, characters 14 and 15 are always spaces. The data is located here . You may use the following code to download this file:

You will read the data from that file, calculate monthly averages, and write a new output file in a similar format.

The assignment is due at 11:59pm on Wednesday, March 6 .

You should submit the completed notebook file required for this assignment on Blackboard . The filename of the notebook should be a4.ipynb . You should not turn in the food-prices-monthly.txt file as your notebook should contain the code to create it.

Please make sure to follow instructions to receive full credit. Use a markdown cell to Label each part of the assignment with the number of the section you are completing. You may put the code for each part into one or more cells. In Parts 3 and 4, CSCI 503 students must compute and output two averages and a percent change while CSCI 490 students need only compute and output one average. Do not use external libraries for reading, parsing, or writing the data files.

0. Name & Z-ID (5 pts)

The first cell of your notebook should be a markdown cell with a line for your name and a line for your Z-ID. If you wish to add other information (the assignment name, a description of the assignment), you may do so after these two lines.

1. Read Data (15 pts)

Either download the file and upload it to Jupyter, or use the provided code above to download the file. Then, use an iterator to read the file food-prices-weekly.txt into a list of dictionaries named data (a format similar to what we used in Assignment 3 ). Remember that the file is encoded as utf-16! Also, remember that a file object will provide an iterator if you pass it to the iter function. Read the header first (the first line), and then the rest of the file. The header will serve as the keys for each dictionary while the other lines are values. To split each line into its column values, use slicing and remove leading and trailing whitespace. You do not need to convert values (e.g. to integers) in this step (see Step 3). When you finish, your data should look like:

  • You can use the encoding keyword argument to the open function to help decode the file.
  • You cannot use split here because some states and categories have spaces in them. Use slicing.
  • Remember that the iter() functions obtains an iterator for an object, and next() retrieves an item. For example, next(iter([1,2,3])) is 1.
  • If you pass an iterator to a for loop, it will loop through the remaining items.
  • strip will be useful to remove whitespace.
  • Use zip to create pairs of tuples that can be used to create a dictionary. dict(zip(['a','b'], [1,2])) produces the dictionary {'a': 1, 'b': 2} .

2. Add Month Column (5 pts)

For each data item, create a new key-value pair, Month , from the Date column. Given a date in yyyy-mm-dd format, the Month value should be yyyy-mm . Add these pairs to the existing dictionaries in the list.

  • You should be able to use slicing to extract the parts of the string for each data item.

3. Compute Monthly Values (15/25 pts)

CSCI 490 students should complete (a) and CSCI 503 students should complete (b)

a. [CSCI 490 Only] (15 pts)

Create a new list of dictionaries named monthly_data that has one entry per month that and contains four key-value pairs ( State , Month , Category , DollarsAvg ). DollarsAvg should be the average of the Dollars values for the given month, state, and category. You will need to convert the individual values to integers before computing averages. monthly_data should look like:

  • To compute an average, you need both the sum and the number of items being averaged. There are several ways to compute this ranging from storing these values as a tuple to storing the individual values in a list.

b. [CSCI 503 Only] (25 pts)

Create a new list of dictionaries named monthly_data that has one entry per month that and contains six key-value pairs ( State , Month , Category , DollarsAvg , LastYearAvg , PctChange ). DollarsAvg and LastYearAvg should be the average of the Dollars and LastYear values, respectively, for the given month, state, and category. However, remember that -999 indicates LastYear is invalid so do not include this value in your averages. Instead, indicate that the value is invalid by using the nan value ( math.nan ). Then, PctChange is computed by \[ 100 \cdot \frac{\texttt{DollarsAvg} - \texttt{LastYearAvg}}{\texttt{DollarsAvg}} \] You will need to convert the individual values to integers before computing averages. Do this efficiently. You shouldn’t loop through the data more than twice (once to read, once to write). At the end, monthly_data should look like:

  • To be efficient, compute DollarsAvg and LastYearAvg at the same time, and create the dictionary for each monthly_data entry by accessing all data related to the (Month, State, Category) tuple at once.

4. Write Output (20/25 pts)

Write the new monthly_data list of dictionaries to a file named food-prices-monthly.txt in a the standard utf-8 format. This means writing the header values as the first line. Second, write the floating point values for DollarsAvg (and for CSCI 503, LastYearAvg ) with only 1 digit after the decimal point. CSCI 503 students should also write PctChange with 2 digits after the decimal point. All the numbers should be right-aligned with at least two spaces between each column. Write a positive sign ( + ) for positive values of PctChange and a negative sign for negative values. The positions of each entry ( inclusive ) should be:

  • Month : (16-22) the month of the data collection in yyyy-mm format
  • Category : (25-51) the food category ( contains spaces )
  • DollarsAvg : (54-64) the average value of sales for the month
  • [CSCI 503] LastYearAvg : (67-77) the average value of sales for the month last year
  • [CSCI 503] PctChange : (80-88) the percent change from the last year

The output file should look like (CSCI 490 students will not have the last two columns):

  • Use print function calls to write a few data items to stdout first, then when you are satisfied the format is correct, write all of the data items to a file.
  • Remember the file keyword argument for the print function.
  • Use a with statement to make sure all data is written to the file (or make sure to call close ).
  • Remember to pass the w flag to open to be able to write to a file.
  • Consult the Format Specification Mini-Language for the various flags
  • You can see the contents of the file you wrote in the notebook using the !cat command: !cat food-prices-monthly.txt

Extra Credit

  • CSCI 490 students may complete the 503 work for extra credit

IMAGES

  1. Assignment 4: String Shortener : r/EdhesiveHelp

    string shortener assignment 4

  2. Assignment 4: String Shortener : r/EdhesiveHelp

    string shortener assignment 4

  3. Assignment 4 String Shortener

    string shortener assignment 4

  4. (Needs Help!)Unit 4 Assignment String Shortener: Second algorithm. Hi

    string shortener assignment 4

  5. Assignment 4 String Shortener

    string shortener assignment 4

  6. Assignment 4 String Shortener.docx

    string shortener assignment 4

VIDEO

  1. JAVA

  2. Assignment 4 String Example

  3. INPUT_OUTPUT_ASSIGNMENT_STATEMENTS

  4. DESIGN A URL SHORTENER

  5. String Esports Rs.1,00,000 BGMI Tournament Qualifiers #1 and #2

  6. Sendbat Close to your customers

COMMENTS

  1. Assignment 4: String Shortener : r/EdhesiveHelp

    Assignment 4: String Shortener. This is my full code. Currently this only gives me a 25% even though it works perfectly fine. import java.util.Scanner; class Assignment4 { public static void main (String [] args) { /* Write your code here */ Scanner scan = new Scanner (System.in); System.out.println ("Type the message to be shortened"); String ...

  2. Unit 4: Iteration

    Assignment 4: String Shortener: Students will design a program which processes a String, determines properties of this String and prints a modified version of the String (Skill 1.A). Students must write iteration statements, decision statements, and String methods to implement this program (Skill 2.B). \n \n

  3. Assignment 4 String Shortener Algorithm 2: How to Prepare

    In this assignment, you will be asked to prepare a string shortener algorithm. This means you will have to define and implement a solution that can do the job. You will have to work with some data structures and algorithms and with at least one programming language. The main goal of this part is to… Read More »Assignment 4 String Shortener Algorithm 2: How to Prepare

  4. GitHub: Let's build from here · GitHub

    {"payload":{"allShortcutsEnabled":false,"fileTree":{"":{"items":[{"name":"Term_1:_Assignment_2-_Time_Converter.java","path":"Term_1:_Assignment_2-_Time_Converter.java ...

  5. DOCX APCSA Course Syllabus

    Assignment 4: String Shortener: Students will design a program which processes a String, determines properties of this String and prints a modified version of the String ( Skill

  6. GitHub

    {"payload":{"allShortcutsEnabled":false,"fileTree":{"":{"items":[{"name":"CSA Assignment Prompts","path":"CSA Assignment Prompts","contentType":"directory"},{"name ...

  7. A concise answer to Assignment 4 string shortener

    The Assignment 4 string shortener is an algorithm that allows for the compression of long strings of text into shorter versions. It achieves this by analyzing the input string and identifying patterns or repeated sequences of characters. By replacing these patterns with shorter representations, the string can be significantly shortened without ...

  8. Solved Assignment 4, String Shortener Instructions In many

    Assignment 4, String Shortener. Instructions. In many methods of communication throughout the last century, from telegrams to SMS messages to tweets, there is a benefit to reducing message length: either the number of characters is limited or using more characters incurs extra cost. Your job in this assignment is to write a program which takes ...

  9. Java String Shortener

    The first thing your program will do is ask the user to type a message which will be stored as a String. If the message contains less than 10 characters the program should print "This doesn't need shortening!" and finish. Otherwise, the message should be immediately converted to lowercase as this will make processing much easier.

  10. Assignment 4 String Shortener

    Assignment 4 String Shortener - iimport java.util.Scanner ... Doc Preview. Pages 2. Total views 100+ Shadow Hills High. CSP. CSP 101. MinisterCheetah2210. 1/28/2020. 50% (4) View full document. Students also studied. Assignment 4, String Shortener.docx. Seminole State College of Florida. MAC 1105. homework.

  11. Assignment 4 String Shortener.docx

    Assignment 4 String Shortener.docx - import... Doc Preview. Pages 2. Total views 100+ Seminole State College of Florida. MAC. MAC 1105. XBEEMAN. 1/24/2020. 60% (5) View full document. Students also studied. Assignment 4, String Shortener. Shadow Hills High. CSP 101. homework. Assignment4_String_Shortener.java.

  12. Jovakan/apcsa2020: Answer key for APCSA Edhesive 2020

    This repository is organized into the units and lessons inside them. You will also find the assignments but you will find no answers to any of the reviews, quizzes, or exams.

  13. [Solved] Assignment 4: String Shortener Ever tried to write a tweet

    Assignment 4: String Shortener. Ever tried to write a tweet that was too long to post? There's nothing particularly new about Twitter's character limit: from the very start of electronic communications, there have been benefits to reducing message length. Telegraph companies in the 19th and early 20th century charged users by the word and had a ...

  14. Assignment 4: String Shortener : r/EdhesiveHelp

    Unit 4: Assignment 4: String Shortener upvotes r/EdhesiveHelp. r/EdhesiveHelp. Need answers for a code practice? We got you! If you need answer for a test, assignment, quiz or other, you've come to the right place. Members Online. Alright bois I got a 100% on the String Shortener. ...

  15. Assignment4 String Shortener2.java

    Assignment 4, String Shortener. Shadow Hills High. CSP 101. homework. ZG_String_Shortener.txt. Warwick High School. MATH 0374. Assignment 4, String Shortener.docx. Seminole State College of Florida. ... import java.util.Scanner; class Assignment_4 { public static void main ( String[] args ) { Scanner scan = new Scanner (System. in ); System ...

  16. GitHub: Let's build from here · GitHub

    {"payload":{"allShortcutsEnabled":false,"fileTree":{"Unit_4":{"items":[{"name":"Assignment4.java","path":"Unit_4/Assignment4.java","contentType":"file"},{"name":"U4 ...

  17. CSCI 503/490

    Use a markdown cell to Label each part of the assignment with the number of the section you are completing. You may put the code for each part into one or more cells. In Parts 3 and 4, CSCI 503 students must compute and output two averages and a percent change while CSCI 490 students need only compute and output one average. Do not use external ...

  18. Assignment4 String Shortener.java

    View Assignment4_String_Shortener.java from CSC DATA STRUC at Point Grey Secondary. /* * NAME: Salina Safi PERIOD: 2-4 DATE: November 22, 2019 * * Description: This program checks to see how long a ... Assignment 4, String Shortener.docx. Seminole State College of Florida. MAC 1105. homework. 4.11 Program_Drawing a half arrow (Java).docx ...

  19. Assignment 4 String ShortenerInstructionsIn many methods of com.docx

    Assignment 4, String Shortener Instructions In many methods of communication throughout the last century, from telegrams to SMS messages to tweets, there is a benefit to reducing message length: either the number of characters is limited or using more characters incurs extra cost. Your job in this assignment is to write a program which takes a message as a string and reduces the number of ...