In Class 10 Exercises - Arrays Assignment Overview Basic use of arrays, using for loop and while loops to fill in and access the array elements. Learning Objectives . Declaring arrays • Understanding the indexing of array elements, how elements are numbered "Subscripting" the array, i.e. indexing • Accessing array elements, i.e. setting elements and using them in calculations Outputing array elements • • Using array elements on the left and right-hand side of expressions, and both . Remembering that the first element in an array is the 0th element Part A Declare an array of 100 int elements, and assign the value (index*index) to each element. For example, arr[3] should be set be equal to 9, arr[5] equal to 25, etc.. Use a for loops. Print the array as in the next box. Use a separate for loop to print the array, one element per line, e.g. arri [0] = 0 arri [1] = 1 arri [2] =4 arri [3] 9 arr1 [99] 9801 Part B 1. Declare an array of 100 int elements, or use the same one. 2. Prompt for a filename and open it to read from it 3. Read 1 number at a time into each element of the array. 4. Use a for loop to read 100 numbers; do not use a while until end-of-file loop because there can be more than 100 numbers in the file! 5. Print the 11, 21", 31", 41, 51" numbers (since indexes start at 0, you are printing arr[10], arr[20], etc.!) a. You do not need a loop or anything special for these 5 lines, you should just use 5 cout statements. 6. Output should look like this, depending on the input file: Input File Name B: input.txt arrB[10] - 11 arrB[20]= -12 arrB[30] - 892 W arrB[40] 28762 arrB[50] -1 Part C Copy the code from Part B. Modify the code to read until end-of-file as well as only read a MAXIMUM of 100 numbers, whichever comes first. Only print the last element in the array, do not print all of the elements in the array. To test this, create a file with only a few numbers in it. Web-CAT will test your program with a small file and with a HUGE file so that your program will NOT work if you do not stop reading after 100 numbers. Output should look like this for a file with just 12 numbers: Input File Name C: inl.in arrc [11] -9786 Or like this if there are 100 or more numbers in the file. You only read the first 100! Input File Name C: in2.in arrC[99] -42 . Test this with exactly 100 mumbers in the file, also, test with 99 mumbers in the file; also, test with 110 numbers, and make sure your code is correct! Test Data 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 98 1 2 3 4 5 96 97

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please complete all parts of the assignment in C++ code and make sure all variable names match to the assignment.

Part D
Only a few lines of this output are actually tested on Web-CAT, so please don't think
that you are only getting those wrong if you see a few error messages; it can means
ALL of the lines are wrong.
Use arrays to calculate the Fibonacci sequence. You must set the first 2 elements equal to
0 and 1, then each of the "next elements" are equal to the previous 2 elements added
together.
fibArr[0]=0
fibArr[1]=1
fibArr[2]=1
fibArr[3]=2
fibArr[4]=3
fibArr[5]=5
fibArr[6]=8
fibArr[7]=13
fibArr[i]=fibArr[i-1]+ fibArr[ i-2]; // This is the code you need in a for loop.
fibArr[8] = fibArr [7] + fibArr[6] => 13+8=21
Start with an array of 100 integer elements. Again, use a for loop to do the calculations,
and then use another for loop to print the values.
This programming problem has previously appeared on the final.
Note what happens when the numbers get really big.
Change the data type for the array to long, and print them again
Note what happens when the numbers get really big. How is this different than when
the data type is int?
Change the data type for the array to long long, and print them again.
Note what happens when the numbers get really big. How is this different than when
the data type is long?
The code with an array of long long elements is the code you should turn in for this part.
Output should look like this:
fibArr [0]=0
fibArr [1]=1
fibArr [2]=1
fibArr [3]=2
fibArr [4]=3
fibArr [5]=5
fibArr [6]=8
fibArr [7]=13
fibArr [8]=21
fibArr [9]=34
fibArr [10]=55
fibArr [99]=-2437933049959450366
Submit your work to Web-CAT
Transcribed Image Text:Part D Only a few lines of this output are actually tested on Web-CAT, so please don't think that you are only getting those wrong if you see a few error messages; it can means ALL of the lines are wrong. Use arrays to calculate the Fibonacci sequence. You must set the first 2 elements equal to 0 and 1, then each of the "next elements" are equal to the previous 2 elements added together. fibArr[0]=0 fibArr[1]=1 fibArr[2]=1 fibArr[3]=2 fibArr[4]=3 fibArr[5]=5 fibArr[6]=8 fibArr[7]=13 fibArr[i]=fibArr[i-1]+ fibArr[ i-2]; // This is the code you need in a for loop. fibArr[8] = fibArr [7] + fibArr[6] => 13+8=21 Start with an array of 100 integer elements. Again, use a for loop to do the calculations, and then use another for loop to print the values. This programming problem has previously appeared on the final. Note what happens when the numbers get really big. Change the data type for the array to long, and print them again Note what happens when the numbers get really big. How is this different than when the data type is int? Change the data type for the array to long long, and print them again. Note what happens when the numbers get really big. How is this different than when the data type is long? The code with an array of long long elements is the code you should turn in for this part. Output should look like this: fibArr [0]=0 fibArr [1]=1 fibArr [2]=1 fibArr [3]=2 fibArr [4]=3 fibArr [5]=5 fibArr [6]=8 fibArr [7]=13 fibArr [8]=21 fibArr [9]=34 fibArr [10]=55 fibArr [99]=-2437933049959450366 Submit your work to Web-CAT
In Class 10 Exercises - Arrays
Assignment Overview
Basic use of arrays, using for loop and while loops to fill in and access the array
elements.
Learning Objectives
• Declaring arrays
Understanding the indexing of array elements, how elements are numbered
"Subscripting" the array, i.e. indexing
Accessing array elements, i.e. setting elements and using them in calculations
• Outputing array elements
Using array elements on the left and right-hand side of expressions, and both
Remembering that the first element in an array is the 0th element
Part A
Declare an array of 100 int elements, and assign the value (index*index) to each element. For
example, arı[3] should be set be equal to 9, arr[5] equal to 25, etc.. Use a for loops.
Print the array as in the next box
Use a separate for loop to print the array, one element per line, e.g.
arr1 [0] = 0
arrl [1]
= 1
arr1 [2] =
arr1 [3] = 9
arri [99] = 9801
Part B
1. Declare an array of 100 int elements, or use the same one.
2. Prompt for a filename and open it to read from it
3. Read 1 number at a time into each element of the array.
4. Use a for loop to read 100 numbers; do not use a while until end-of-file loop because
there can be more than 100 numbers in the file!
5.
Print the 11th, 21, 31, 41, 51" numbers (since indexes start at 0, you are printing
arr[10], arr[20], etc.!)
a. You do not need a loop or anything special for these 5 lines, you should just use
5 cout statements.
6. Output should look like this, depending on the input file:
Input File Name B: input.txt
arrB [10]
= 11
arrB [20]
-12
arrB[30] = 892
arrB[40] = 28762
arrB[50] = -1
1
Part C
Copy the code from Part B. Modify the code to read until end-of-file as well as only
read a MAXIMUM of 100 numbers, whichever comes first. Only print the last element in
the array, do not print all of the elements in the array. To test this, create a file with only a
few numbers in it.
10
Web-CAT will test your program with a small file and with a HUGE file so that
your program will NOT work if you do not stop reading after 100 numbers.
Output should look like this for a file with just 12 numbers:
Input File Name C: inl.in
arrC [11] = -9786
Or like this if there are 100 or more numbers in the file. You only read the first 100!
Input File Name C: in2.in
arrC[99] = -42
• Test this with exactly 100 numbers in the file; also, test with 99 numbers in the file; also,
test with 110 numbers; and make sure your code is correct!
Test Data
1 2 3 4 5
6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
6 7 8 9 10
6 7 8 9 10
6 7 8 9 10
5 6 7 8 9 10
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4
1 2 3 4 5
6 7 8 9 10
1 2 3 4
5
96 97 98
Transcribed Image Text:In Class 10 Exercises - Arrays Assignment Overview Basic use of arrays, using for loop and while loops to fill in and access the array elements. Learning Objectives • Declaring arrays Understanding the indexing of array elements, how elements are numbered "Subscripting" the array, i.e. indexing Accessing array elements, i.e. setting elements and using them in calculations • Outputing array elements Using array elements on the left and right-hand side of expressions, and both Remembering that the first element in an array is the 0th element Part A Declare an array of 100 int elements, and assign the value (index*index) to each element. For example, arı[3] should be set be equal to 9, arr[5] equal to 25, etc.. Use a for loops. Print the array as in the next box Use a separate for loop to print the array, one element per line, e.g. arr1 [0] = 0 arrl [1] = 1 arr1 [2] = arr1 [3] = 9 arri [99] = 9801 Part B 1. Declare an array of 100 int elements, or use the same one. 2. Prompt for a filename and open it to read from it 3. Read 1 number at a time into each element of the array. 4. Use a for loop to read 100 numbers; do not use a while until end-of-file loop because there can be more than 100 numbers in the file! 5. Print the 11th, 21, 31, 41, 51" numbers (since indexes start at 0, you are printing arr[10], arr[20], etc.!) a. You do not need a loop or anything special for these 5 lines, you should just use 5 cout statements. 6. Output should look like this, depending on the input file: Input File Name B: input.txt arrB [10] = 11 arrB [20] -12 arrB[30] = 892 arrB[40] = 28762 arrB[50] = -1 1 Part C Copy the code from Part B. Modify the code to read until end-of-file as well as only read a MAXIMUM of 100 numbers, whichever comes first. Only print the last element in the array, do not print all of the elements in the array. To test this, create a file with only a few numbers in it. 10 Web-CAT will test your program with a small file and with a HUGE file so that your program will NOT work if you do not stop reading after 100 numbers. Output should look like this for a file with just 12 numbers: Input File Name C: inl.in arrC [11] = -9786 Or like this if there are 100 or more numbers in the file. You only read the first 100! Input File Name C: in2.in arrC[99] = -42 • Test this with exactly 100 numbers in the file; also, test with 99 numbers in the file; also, test with 110 numbers; and make sure your code is correct! Test Data 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 6 7 8 9 10 6 7 8 9 10 6 7 8 9 10 5 6 7 8 9 10 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 96 97 98
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 10 images

Blurred answer
Knowledge Booster
Program on Numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education