I always give a positive rating! Language is C++ I know this looks really long, but this is actually pretty easy. Just f
Posted: Sat May 14, 2022 2:48 pm
I always give a positive rating!
Language is C++
I know this looks really long, but this is actually
pretty easy.
Just follow the steps in the document below and paste
your code in the answer.
Thanks!
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 clements, how elements are numbered "Subscripting" the array, i.e. indexing Accessing array elements, i.e. setting elements and using them in calculations Outputing array clements Using array clements on the left- and right-hand side of expressions, and both • Remembering that the first element in an array is the oth clement . Part A Declare an array of 100 int elements, and assign the value (index*index) to each element. For exainple, 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. Usc a scparalc for loop lo print the array, onc clement per linc,c.g. arri [0] = 0 arri[1] = 1 arri[2] = 4 arri [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 cach clement 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, 314, 415, 5 il numbers (since indexes start at 0, you are printing arr|101. arr|20), etc.!) You do not need a loop or anything special for these 5 lines, you should just use 5 coul statements. 6. Output should look like this, depending on the input file: a 1
Input File Name B: input.txt arrB[10] = 11 arrB[20] = -12 arrB[30] = 892 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 lew 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 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 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 96 97 98 2
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 O and 1, then each of the "next elements" are equal to the previous 2 elements added together. fibArt[0]=0 fibArr[1]=1 fibArr(2-1 fibArr[3]=2 fibArr[4]=3 fibArt[5]=5 fibArt[6]=8 fibArr|71-13 + fibArr| i l=fibArr| 1-1 | + fibArr| 1-2; // This is the code you need in a for loop. fibArr|8] = fibArr|71 + 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 clements is the code you should turn in for this part. Output should look like this: 3
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 4
Language is C++
I know this looks really long, but this is actually
pretty easy.
Just follow the steps in the document below and paste
your code in the answer.
Thanks!
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 clements, how elements are numbered "Subscripting" the array, i.e. indexing Accessing array elements, i.e. setting elements and using them in calculations Outputing array clements Using array clements on the left- and right-hand side of expressions, and both • Remembering that the first element in an array is the oth clement . Part A Declare an array of 100 int elements, and assign the value (index*index) to each element. For exainple, 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. Usc a scparalc for loop lo print the array, onc clement per linc,c.g. arri [0] = 0 arri[1] = 1 arri[2] = 4 arri [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 cach clement 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, 314, 415, 5 il numbers (since indexes start at 0, you are printing arr|101. arr|20), etc.!) You do not need a loop or anything special for these 5 lines, you should just use 5 coul statements. 6. Output should look like this, depending on the input file: a 1
Input File Name B: input.txt arrB[10] = 11 arrB[20] = -12 arrB[30] = 892 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 lew 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 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 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 96 97 98 2
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 O and 1, then each of the "next elements" are equal to the previous 2 elements added together. fibArt[0]=0 fibArr[1]=1 fibArr(2-1 fibArr[3]=2 fibArr[4]=3 fibArt[5]=5 fibArt[6]=8 fibArr|71-13 + fibArr| i l=fibArr| 1-1 | + fibArr| 1-2; // This is the code you need in a for loop. fibArr|8] = fibArr|71 + 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 clements is the code you should turn in for this part. Output should look like this: 3
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 4