# CP 120 chp2.1

### 14 terms by ca30midterm

#### Study  only

Flashcards Flashcards

Scatter Scatter

Scatter Scatter

## Create a new folder

MIDTERM

variable

### Which of the following is NOT a legal identifier? outrageouslyAndShockinglyLongRun _42 _ loveportionnumber9 7thheaven

7th heaven

*** can not start with a number

_____

declared

### Declare two integer variables named profitStartOfQuarter and cashFlowEndOfYear .

int profitStartOfQuarter;
int cashFlowEndOfYear;

### Write a statement that declares an int variable named count . Write a declaration for two integer variables, age and weight. Declare an integer variable named degreesCelsius .

int count;

int age;
int weight;

int degreesCelsius;

### ASSIGNMENTS 1. Given an integer variable drivingAge that has already been declared, write a statement that assigns the value 17 to drivingAge . 2. Write a statement to set the value of num to 4 (num is a variable that has already been declared). 3. Given two integer variables num and highest, write a statement that gives highest the same value that num has. 4. Given two integer variables oldRecord and newRecord , write a statement that gives newRecord the same value that oldRecord has. 5. Given two integer variables matricAge and gradAge , write a statement that gives gradAge a value that is 4 more than the value of matricAge . 6. Write a statement to add the values of x and y together, storing the result in sum. (The variables have already been declared and x and y have already been initialized.)

1. drivingAge = 17;

2. num =4;

3. higest = num;

4. newRecord = oldRecord;

5. gradAge = matricAge + 4;

6. sum=x+y;

jtemp = j;
itemp=i;
j= itemp;
i=jtemp;

temp = i;
i=j;
j=temp;

### *** Given two int variables, firstPlaceWinner and secondPlaceWinner , write some code that swaps their values. Declare any additional variables as necessary, but do not redeclare firstPlaceWinner and secondPlaceWinner .

int i;
i=firstPlaceWinner;
firstPlaceWinner = secondPlaceWinner;
secondPlaceWinner = i;

int age;
age=15;
int weight;
weight=90;

int age;
age= 18;
float weight;
weight=114.5;

hasFever

mightBePrime

Example:

## Press Ctrl-0 to reset your zoom

### Please upgrade Flash or install Chrometo use Voice Recording.

For more help, see our troubleshooting page.

Create Set