Description
Unformatted Attachment Preview
CIT-237
Lab 7.1
Arrays
The goal of this lab is to help you get familiar with arrays.
Due Date
You must demonstrate the solution to this lab exercise to the instructor by Wednesday, February 19, 2020, in
order to receive full credit for this work.
Lab Setup
1. Create the project using Visual Studio.
2. Download the ZIP file for Lab 7.1 from Moodle.
3. Copy the sample input files, numbers.txt, and fiveNumbers.txt from the ZIP file to the
same folder where your source file is located.
Programming Exercise
This lab exercise involves writing a program with several functions:
The “main” function must:
Define an array of 12 integers:
Prompt the user for an input file name. Open this file for input. The file contains integers (one per line).
Read the contents of the file into the array.
Call four separate functions: getLowest, getHighest, getSum, and getAverage, and display the value
returned by each function.
const int ARRAY_SIZE = 12;
int numbers[ARRAY_SIZE];
Each of the other functions must contain a loop that scans the data in the array and returns the appropriate result:
The getLowest function returns the lowest number in the array.
The getHighest function returns the highest number in the array.
The getSum function returns the total of the numbers in the array.
The getAverage function returns the average of the numbers in the array.
Design Restriction
For this lab exercise use an array of integers, not a vector of integers. We will use vectors later in the course, but
for now we need to use only arrays.
Sample Data Files and Sample Program Output
The ZIP file, which can be downloaded from Moodle, contains two text files. These should be used to test your
program. (They are also shown on the next page.)
CIT237_Lab07.1_Arrays_20200210.docx
2/7/2020 11:43 PM
page 1 of 2
CIT-237
Lab 7.1
Arrays
The sample data and sample program output are provided below. (In the sample program output shown in this
document, text typed by the user is shown in BOLD font. In actuality, all text will be displayed in the same font)
Input file: numbers.txt
53
22
87
103
-3
75
220
1
64
543
98
44
Output from processing the numbers.txt file
Enter name of input file: numbers.txt
12 numbers read from input file.
The highest value is 543
The lowest value is -3
The sum of the numbers is 1307
The average of the numbers is 108.917
Press any key to continue . . .
Input file: fiveNumbers.txt
-53
-22
-87
-103
-3
Output from processing the fiveNumbers.txt file
Enter name of input file: fiveNumbers.txt
5 numbers read from input file.
The highest value is -3
The lowest value is -103
The sum of the numbers is -268
The average of the numbers is -53.6
Press any key to continue . . .
CIT237_Lab07.1_Arrays_20200210.docx
2/7/2020 11:43 PM
page 2 of 2
Numbers.txt
53
22
87
103
-3
75
220
1
64
543
98
44
fiveNumbers.txt
-53
-22
-87
-103
-3
otherFile.txt
953
322
6687
9103
-67563
5475
6220
551
6664
253
Purchase answer to see full attachment
Purchase answer to see full attachment
Explanation & Answer:
1 program
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Explanation & Answer
Review
Review
Anonymous
Super useful! Studypool never disappoints.
Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4
24/7 Homework Help
Stuck on a homework question? Our verified tutors can answer all questions, from basic math to advanced rocket science!
Most Popular Content
4 pages
Copyrights Questions And Answers
Question 1: Should anyone be allowed to use any copyrighted work without permission and People should only use copyrighted ...
Copyrights Questions And Answers
Question 1: Should anyone be allowed to use any copyrighted work without permission and People should only use copyrighted material without permission ...
Android App Unit 2
For this IP, you will create a very simple drawing app using Android Studio. The purpose of this assignment is to give you ...
Android App Unit 2
For this IP, you will create a very simple drawing app using Android Studio. The purpose of this assignment is to give you more building blocks to use when programming apps. For full credit for this assignment, you should complete the following:
Create a menu and display menu items on the app bar
Detect when the user touches the screen and moves a finger
Be able to change the color and width of a line
Be able to save an imageTo turn in this assignment, upload screenshots of the working app (from the emulator) as a Word document.The screenshots need to show that the app works and that all of the parts listed work. At a minimum, students should upload 2 screenshots showing:
A drawing
Menu showing the different color choices and line widths
12 pages
R Programming
Using R, calculate the summary statistics (minimum, maximum, mean, median, and standard deviation) and create a histogram ...
R Programming
Using R, calculate the summary statistics (minimum, maximum, mean, median, and standard deviation) and create a histogram of sale price for each ...
Oregon State University Black Lives Matter Database of Resources Discussion
Black Lives Matter DatabaseIn 2020, in the wake of the death of George Floyd and Breyona Taylor, and in response to so man ...
Oregon State University Black Lives Matter Database of Resources Discussion
Black Lives Matter DatabaseIn 2020, in the wake of the death of George Floyd and Breyona Taylor, and in response to so many other black deaths at the hands of police, people began to organize protests all over the country (and indeed, all over the world). Karen was a student at UWB during this time, and she watched the protests on the internet, and she read her friends’ posts about the protests on social media. To be honest, she had never really spent much time thinking about these things. She had thought of herself as “not political”. But now, she began to feel some embarrassment about that. She began to realize that this “not political” stance just allowed her to remain ignorant and passive about things that were actually really really important, and it was just an excuse to stand by and do nothing. So she resolved to educate herself about the Black Lives Matter movement and all the connected issues so that she could then take a more active role in trying to make the world a better place for her fellow citizens -- and especially for black and indigenous people and people of color. She began reading books, looking up different organizations on the internet, and watching movies. As she did, she thought it might be nice to compile these different resources she was finding into some easy-to-access database so that other people who wanted to educate themselves could more easily find them.Karen was also a student in CSS 143, and so she decided to put her Java skills to use by building a database of these resources as a part of her project. She called it BLMDB (Black Lives Matter Database). The BLMDB class she built was pretty cool. She called each resource a ‘record’, and there were three different kinds of records: Movies, Books, and Online sources. Her BLMDB could display all the records, or just some of them. It could sort them. You could even choose different criteria to sort them by. It could even sort them based on multiple criteria, like first by year, then by name. You could import records from a text file into the database, or you could manually enter records. You could export the records back to a text file.Your instructor for CSS 143 paired you with Karen to work on your CSS 143 project together and you were excited (and a little bit guilty) because she had already done almost all the work creating this BLMDB, and it was basically done. But then disaster struck. First, Karen’s dog jumped up and tried to eat her laptop. (It’s the modern equivalent of “The dog ate my homework”.) The laptop fell off the table and the hard drive was damaged. Sadly, she hadn’t saved her work in the cloud. (What was she THINKING?) When she restarted it, a bunch of the files were missing, and some of the files that were there were partially erased. Many of the methods in some of the classes she built only had the Javadoc but not the method. It was a mess. And then, to make matters worse, Karen got really sick and had to go to the hospital. She sent you all the java files she had, and now it’s all up to you to restore the project to its former glory. (I suppose it’s only fair since she did all the work up to this point.) Don't erase anything that she has (except maybe the comments like "//[OH NO THIS GOT ERASED!]" ). Just add back the missing parts. Luckily, Karen practiced really good coding style and always wrote good comments (especially Javadoc comments), and that is going to be really helpful for you in figuring out what you need to reconstruct. Just make sure you uphold her high standards for good coding style. Right before Karen went into the hospital, she also asked you one more favor. She was compiling the list of resources for people to learn about racism and race-related issues, and most of what she had found so far is there in a text file. But she felt like the list of resources could be longer. So she asked you if you could do a little research and find at least one more of each of the three kinds of records (a movie, a book, an online source like an article or organization) that you could add to the text file. If you want to find more than one of each, that would be even better. But at least one of each.Here’s what we know about the project so far. (After this, you’ll just have to go through the files and try to figure it out yourself. For example, if you see a method being called, but that method doesn’t exist, you better go create that method.)BLMDB.java. This is the primary class, and it has a main method that is the driver for the whole thing. Luckily, this class seems to be mostly intact. Inside of it, it has an instance variable of the type RecordList. Take a look and see what methods this class calls, and see if you can figure out if it's missing anything. Also in BLMDB there's a runAllTests() method but it seems to be empty. You'll have to fill it up with all the tests you can think of. It's your job to figure out what you need to check for and figure out how to write tests that can make it clear on the console what tests passed and what didn't. I STRONGLY encourage you to write tests as you go along and not just att the very end. If you want to, in the runAllTests() method, you might want to run a bunch of other little test methods that you write.RecordList.java. The RecordList is just an ArrayList of Records. (Thus, it’s top line is “public class RecordList extends ArrayList<Record>”) But it adds some methods that a regular ArrayList doesn’t have. In particular, it adds a method called sortBy(), in which you can tell it what criterion you want to use to sort it by. (For instance, if you want to sort the records by their description, you could call sortBy(“description”). If you want to sort by their identifier (like the name of the book), you could call sortBy(“identifier”). The sort she had was a version of Insertion Sort -- which is good because Insertion Sort is a stable sort, and that’s important if you’re going to be sorting by multiple criteria. Luckily, Karen had found some code online somewhere for the Insertion Sort method, but unfortunately, the code she found was for sorting an array of ints, and you’ll be sorting an ArrayList of Records, so there will be some differences in the code. There are probably some other helper methods you’ll need here too.ArrayList.java. Of course, you can’t use Java’s built-in ArrayList, you need to build your own. (Sadly, Karen's ArrayList was completely erased.) And your ArrayList needs to be generic, so that you can do things like “ArrayList<Record> r = new ArrayList<Record>();” If your ArrayList isn’t generic yet, you might want to start here.You also might want to add some methods to your ArrayList (or else to your RecordList) that help with your sorting method. For example, a common thing to do in a sorting method is to overwrite an element of an array: myArray[10] = newValue. You might need to write a method so that you can do something like myArrayList.overwrite(10, newValue);In general, if there are any methods called in Karen's classes that look like they're methods of ArrayList (or RecordsList), be sure you have them. If you don't have them, create them.The ArrayList you use could be implemented with a Linked List or with a regular array that resizes when needed.Record.java. This one, luckily, looks fully intact. Take a look at it because it will help you understand other parts of the project. This is the parent class for OnlineRec, Book, and Movie. Notice that the Record class implements the CompareToByInterface.OnlineRec.java , Book.java, and Movie.java. These classes are children of the Record class, but they each add a little more information appropriate to the kind of records that they are. For example, the Book record adds an author and publication year. OnlineRec adds websiteURL. Movie adds a director and a year. These all have to implement the compareToBy method since they are all Records and Record implements CompareToByInterface.CompareToByInterface. Luckily this one is pretty intact as well. Check it out so you know how to build this method in the OnlineRec, Book, and Movie classes.BLM_resources.txt. This is the text file that holds the resources Karen found so far. See if you can figure out the format they need to be in, in order to be read by the BLMDB's import-from-file method. You need to add some more sources to this file.Here are Karen's files (or what's left of them): Will be given to accepted tutorWHAT TO TURN INTurn in a zip drive with all these files in it:BLMDB.javaRecordList.javaRecord.java (this one should be unchanged)CompareToByInterface.java (this one should be unchanged)ArrayList.java (the generic one you made. Also include any other files needed by it. For example, if it inherits from your List.java or if it employs the LinkedListException.java class you made include those.)OnlineRec.javaBook.javaMovie.javaBLM_resources.txt -- with your additional (properly formatted) resourcesALSO: When you turn everything in, you must write a small report in the comments box that pops up when you submit. Let me know what parts you got working , what parts don't, or still need work. Let me know if you feel your coding style is top-notch or needs improving.
Similar Content
Discusssion post, simple and direct to the point
HTML is the standard language used for creating websites. Often, additional languages are used as well. The complementary ...
KMJ Permutation Cipher in C++ Programming Code
HelloI have an assignment using C++For the Homework, you can find it atHomeWork Fileand Please use the eclipse c++ for edi...
SU Programming C++
use what you learnt in c++and come up with a working project code. you must use function and switch...
Harvard University Computer Programming Computer Science Questions
need some coding expert....
CSIS 212 Liberty University Creating a Program in Java Using an IDE Application
The programming questions must be done in java with comments.Question 1, 4, 5 must be done with an IDE and I must be able ...
Santa Monica College Java Question
PLATFORM INDEPENDENCEPlease see Syllabus for more information.Your solution has to be platform-independent; it must run on...
Case Study Questions
Discuss the Services Offered by LinkedIn And Indeed.Com. (2 Marks) LinkedIn is an employee-related social network that is ...
Solution 285
Monthly Expenses for Tom and Sally (January - March)...
Ir 1
In [23]: pg.corr(x=df['sepal_length'], y=df['sepal_width']) In [74]: g = sns.JointGrid(data=df, x='sepal_length', y='sepal...
Related Tags
Book Guides
Epic of Gilgamesh
by Unknown
Macbeth
by William Shakespeare
Hiroshima
by John Hersey
Night
by Elie Wiesel
Crippled America
by Donald J Trump
Cry the Beloved Country
by Alan Paton
The House of the Seven Gables
by Nathaniel Hawthorne
How to Win Friends and Influence People
by Dale Carnegie
Twilight
by Stephenie Meyer
Get 24/7
Homework help
Our tutors provide high quality explanations & answers.
Post question
Most Popular Content
4 pages
Copyrights Questions And Answers
Question 1: Should anyone be allowed to use any copyrighted work without permission and People should only use copyrighted ...
Copyrights Questions And Answers
Question 1: Should anyone be allowed to use any copyrighted work without permission and People should only use copyrighted material without permission ...
Android App Unit 2
For this IP, you will create a very simple drawing app using Android Studio. The purpose of this assignment is to give you ...
Android App Unit 2
For this IP, you will create a very simple drawing app using Android Studio. The purpose of this assignment is to give you more building blocks to use when programming apps. For full credit for this assignment, you should complete the following:
Create a menu and display menu items on the app bar
Detect when the user touches the screen and moves a finger
Be able to change the color and width of a line
Be able to save an imageTo turn in this assignment, upload screenshots of the working app (from the emulator) as a Word document.The screenshots need to show that the app works and that all of the parts listed work. At a minimum, students should upload 2 screenshots showing:
A drawing
Menu showing the different color choices and line widths
12 pages
R Programming
Using R, calculate the summary statistics (minimum, maximum, mean, median, and standard deviation) and create a histogram ...
R Programming
Using R, calculate the summary statistics (minimum, maximum, mean, median, and standard deviation) and create a histogram of sale price for each ...
Oregon State University Black Lives Matter Database of Resources Discussion
Black Lives Matter DatabaseIn 2020, in the wake of the death of George Floyd and Breyona Taylor, and in response to so man ...
Oregon State University Black Lives Matter Database of Resources Discussion
Black Lives Matter DatabaseIn 2020, in the wake of the death of George Floyd and Breyona Taylor, and in response to so many other black deaths at the hands of police, people began to organize protests all over the country (and indeed, all over the world). Karen was a student at UWB during this time, and she watched the protests on the internet, and she read her friends’ posts about the protests on social media. To be honest, she had never really spent much time thinking about these things. She had thought of herself as “not political”. But now, she began to feel some embarrassment about that. She began to realize that this “not political” stance just allowed her to remain ignorant and passive about things that were actually really really important, and it was just an excuse to stand by and do nothing. So she resolved to educate herself about the Black Lives Matter movement and all the connected issues so that she could then take a more active role in trying to make the world a better place for her fellow citizens -- and especially for black and indigenous people and people of color. She began reading books, looking up different organizations on the internet, and watching movies. As she did, she thought it might be nice to compile these different resources she was finding into some easy-to-access database so that other people who wanted to educate themselves could more easily find them.Karen was also a student in CSS 143, and so she decided to put her Java skills to use by building a database of these resources as a part of her project. She called it BLMDB (Black Lives Matter Database). The BLMDB class she built was pretty cool. She called each resource a ‘record’, and there were three different kinds of records: Movies, Books, and Online sources. Her BLMDB could display all the records, or just some of them. It could sort them. You could even choose different criteria to sort them by. It could even sort them based on multiple criteria, like first by year, then by name. You could import records from a text file into the database, or you could manually enter records. You could export the records back to a text file.Your instructor for CSS 143 paired you with Karen to work on your CSS 143 project together and you were excited (and a little bit guilty) because she had already done almost all the work creating this BLMDB, and it was basically done. But then disaster struck. First, Karen’s dog jumped up and tried to eat her laptop. (It’s the modern equivalent of “The dog ate my homework”.) The laptop fell off the table and the hard drive was damaged. Sadly, she hadn’t saved her work in the cloud. (What was she THINKING?) When she restarted it, a bunch of the files were missing, and some of the files that were there were partially erased. Many of the methods in some of the classes she built only had the Javadoc but not the method. It was a mess. And then, to make matters worse, Karen got really sick and had to go to the hospital. She sent you all the java files she had, and now it’s all up to you to restore the project to its former glory. (I suppose it’s only fair since she did all the work up to this point.) Don't erase anything that she has (except maybe the comments like "//[OH NO THIS GOT ERASED!]" ). Just add back the missing parts. Luckily, Karen practiced really good coding style and always wrote good comments (especially Javadoc comments), and that is going to be really helpful for you in figuring out what you need to reconstruct. Just make sure you uphold her high standards for good coding style. Right before Karen went into the hospital, she also asked you one more favor. She was compiling the list of resources for people to learn about racism and race-related issues, and most of what she had found so far is there in a text file. But she felt like the list of resources could be longer. So she asked you if you could do a little research and find at least one more of each of the three kinds of records (a movie, a book, an online source like an article or organization) that you could add to the text file. If you want to find more than one of each, that would be even better. But at least one of each.Here’s what we know about the project so far. (After this, you’ll just have to go through the files and try to figure it out yourself. For example, if you see a method being called, but that method doesn’t exist, you better go create that method.)BLMDB.java. This is the primary class, and it has a main method that is the driver for the whole thing. Luckily, this class seems to be mostly intact. Inside of it, it has an instance variable of the type RecordList. Take a look and see what methods this class calls, and see if you can figure out if it's missing anything. Also in BLMDB there's a runAllTests() method but it seems to be empty. You'll have to fill it up with all the tests you can think of. It's your job to figure out what you need to check for and figure out how to write tests that can make it clear on the console what tests passed and what didn't. I STRONGLY encourage you to write tests as you go along and not just att the very end. If you want to, in the runAllTests() method, you might want to run a bunch of other little test methods that you write.RecordList.java. The RecordList is just an ArrayList of Records. (Thus, it’s top line is “public class RecordList extends ArrayList<Record>”) But it adds some methods that a regular ArrayList doesn’t have. In particular, it adds a method called sortBy(), in which you can tell it what criterion you want to use to sort it by. (For instance, if you want to sort the records by their description, you could call sortBy(“description”). If you want to sort by their identifier (like the name of the book), you could call sortBy(“identifier”). The sort she had was a version of Insertion Sort -- which is good because Insertion Sort is a stable sort, and that’s important if you’re going to be sorting by multiple criteria. Luckily, Karen had found some code online somewhere for the Insertion Sort method, but unfortunately, the code she found was for sorting an array of ints, and you’ll be sorting an ArrayList of Records, so there will be some differences in the code. There are probably some other helper methods you’ll need here too.ArrayList.java. Of course, you can’t use Java’s built-in ArrayList, you need to build your own. (Sadly, Karen's ArrayList was completely erased.) And your ArrayList needs to be generic, so that you can do things like “ArrayList<Record> r = new ArrayList<Record>();” If your ArrayList isn’t generic yet, you might want to start here.You also might want to add some methods to your ArrayList (or else to your RecordList) that help with your sorting method. For example, a common thing to do in a sorting method is to overwrite an element of an array: myArray[10] = newValue. You might need to write a method so that you can do something like myArrayList.overwrite(10, newValue);In general, if there are any methods called in Karen's classes that look like they're methods of ArrayList (or RecordsList), be sure you have them. If you don't have them, create them.The ArrayList you use could be implemented with a Linked List or with a regular array that resizes when needed.Record.java. This one, luckily, looks fully intact. Take a look at it because it will help you understand other parts of the project. This is the parent class for OnlineRec, Book, and Movie. Notice that the Record class implements the CompareToByInterface.OnlineRec.java , Book.java, and Movie.java. These classes are children of the Record class, but they each add a little more information appropriate to the kind of records that they are. For example, the Book record adds an author and publication year. OnlineRec adds websiteURL. Movie adds a director and a year. These all have to implement the compareToBy method since they are all Records and Record implements CompareToByInterface.CompareToByInterface. Luckily this one is pretty intact as well. Check it out so you know how to build this method in the OnlineRec, Book, and Movie classes.BLM_resources.txt. This is the text file that holds the resources Karen found so far. See if you can figure out the format they need to be in, in order to be read by the BLMDB's import-from-file method. You need to add some more sources to this file.Here are Karen's files (or what's left of them): Will be given to accepted tutorWHAT TO TURN INTurn in a zip drive with all these files in it:BLMDB.javaRecordList.javaRecord.java (this one should be unchanged)CompareToByInterface.java (this one should be unchanged)ArrayList.java (the generic one you made. Also include any other files needed by it. For example, if it inherits from your List.java or if it employs the LinkedListException.java class you made include those.)OnlineRec.javaBook.javaMovie.javaBLM_resources.txt -- with your additional (properly formatted) resourcesALSO: When you turn everything in, you must write a small report in the comments box that pops up when you submit. Let me know what parts you got working , what parts don't, or still need work. Let me know if you feel your coding style is top-notch or needs improving.
Earn money selling
your Study Documents