{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

REC01_Problems_Solutions

# REC01_Problems_Solutions - 1 14:440:127 Introduction to...

This preview shows pages 1–3. Sign up to view the full content.

1 14:440:127– Introduction to Computers for Engineers Recitation 01 Problems Solutions Rutgers University, Spring 2011 Instructor - Brenda V. Cortez 1. Determine which of the following identifiers are valid or invalid. If any are invalid write why. 3 times Invalid because you can’t start an identifier with a number Cost Valid My Age Invalid because you can’t have spaces false Invalid because this is a reserved keyword grade Valid passed Invalid because you can’t have symbols as part of an identifier #one Again, invalid because you can’t have special symbols as part of an identifier var1 Valid frequency Valid 2. Create a variable of type int and another of type float , and store 23.01 in each. Subtract one from the each of the values of the variables. Add two to the values of the variables and print them to the screen. Explain what happens. int k = 23.01; float t = 23.01; cout<< (k-1) + 2 << endl; cout<< (t-1) + 2 << endl; k has a value of 23.01 which is a fractional number, meaning that there is a decimal value to it, and by using the int data type, it is being truncated. 3. Create a variable of type int , assign an integer value to it, and print it to the screen. int k = 23; cout<< k <<endl;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 4. Create a program that asks the user to enter a decimal number and print it to the screen. float decNum; cout<<‘‘Enter a decimal number: ’’; cin>>decNum; cout<<‘‘You entered ’’<<decNum<<endl; 5. Create a program that asks the user to enter a single character and then print a message to the screen saying “You entered the character: ”, where “ ” is the character the user entered. char k; cout<< ‘‘Enter a character: ’’; cin>>k; cout<< ‘‘You entered the character: ’’ << k << endl; 6. What does the following program print to the screen? Assume x = 3 and y = 5 . Do this by hand first and then type in the code. If there are any errors, explain what they are and fix them. cout<< x; cout<< x + x; cout<<‘‘x = ’’; cout<<‘‘x = ’’<< x; cout<< x + y << ‘‘ = ’’ << y + x; z = x + y; // what is wrong? cout<<‘‘\n’’; First of all, variable z is never declared, so in order for the program to compile correctly, z has to be declared before it can be used and the output is: 36x = x = 38 = 8 because no new lines are being inserted until the end.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 7

REC01_Problems_Solutions - 1 14:440:127 Introduction to...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online