Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Arrays and Trigonometry Exercises for CPSC 220, Assignments of Computer Science

Exercises on arrays and trigonometry concepts, including declaring an array of cosines, using the law of cosines to find the length of a triangle side, and identifying issues with array initialization. It also covers array size determination and printing arrays.

Typology: Assignments

Pre 2010

Uploaded on 08/13/2009

koofers-user-wyb
koofers-user-wyb 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Arrays Warm Up CPSC 220.
1. Declare an array named cosine with 360 elements each of type double.
2. Suppose the variable d represents the measure of an angle in degrees. Then its
measure in radians is d/180.0. Write the statements necessary so that each of the
elements of the elements holds the cosine of the corresponding angle. That is,
cosine[d] is the trigonometric cosine of the angle whose measure is d.
3. Given a triangle with sides a, b and c and angle X, the Law of Cosines states
c2 = a2 + b2 - (2)(a)(b)(cos X).
Write the code to read in two doubles, representing the length of two of the sides of a
triangle, the measure of the angle X., and then to determine the length of the third
side using the array cosine.
4. How many elements are in each of the following arrays?
a. int x[27];
b. const int base = 10;
int y[base+5];
c. int z[100][100][100][100];
5. What’s wrong with following code segment?
int pep[100];
for( int index =1; index <=100; index++)
pep[index] = 0;
6. What’s wrong with the following code segment?
int pep[2][3] = {
{1,2},
{5,9},
{0,-3}
};
7. Given the following declaration:
int pep [12] [15];
a. Write a loop to print the first row of the array on one line on cout.
b. Write a loop to print the first column on the array on one line on cout.
c. Write a loop to print the first seven rows of the array, each on a single line.
d. Write a loop to print the entire array backwards and upside down, so that
the last line appears first, with last column on the left.

Partial preview of the text

Download Arrays and Trigonometry Exercises for CPSC 220 and more Assignments Computer Science in PDF only on Docsity!

Arrays Warm Up CPSC 220.

  1. Declare an array named cosine with 360 elements each of type double.
  2. Suppose the variable d represents the measure of an angle in degrees. Then its measure in radians is d/180.0. Write the statements necessary so that each of the elements of the elements holds the cosine of the corresponding angle. That is, cosine[d] is the trigonometric cosine of the angle whose measure is d.
  3. Given a triangle with sides a, b and c and angle X, the Law of Cosines states c^2 = a^2 + b^2 - (2)(a)(b)(cos X). Write the code to read in two doubles, representing the length of two of the sides of a triangle, the measure of the angle X., and then to determine the length of the third side using the array cosine.
  4. How many elements are in each of the following arrays? a. int x[27]; b. const int base = 10; int y[base+5]; c. int z[100][100][100][100];
  5. What’s wrong with following code segment? int pep[100]; for( int index =1; index <=100; index++) pep[index] = 0;
  6. What’s wrong with the following code segment? int pep[2][3] = { {1,2}, {5,9}, {0,-3} };
  7. Given the following declaration: int pep [12] [15]; a. Write a loop to print the first row of the array on one line on cout. b. Write a loop to print the first column on the array on one line on cout. c. Write a loop to print the first seven rows of the array, each on a single line. d. Write a loop to print the entire array backwards and upside down, so that the last line appears first, with last column on the left.