Test 1, CSCI 130, Fall 2011
- Please answer each question fully, carefully and thoughtfully.
- No credit will be given for unreadable answers, please write neatly.
- Answer the questions in any order, but please number each answer clearly.
- Make sure that your name is on the test.
- [4 points] Algorithms
- What is an algorithm?
- How is an algorithm used in the program development cycle?
- [4 points] Problem Solving: Name and Describe two problem solving strategies described in the book.
- [6 points] Identifier
- What is an identifier?
- Give the syntax rules for creating an identifier.
- Draw a rectangle around one identifier on the back of this page.
- [6 points] Variables
- What is a variable?
- How is a variable different from an constant?
- Give the conventions for naming a variable for this class.
- Draw an oval around one variable on the back of this page.
- [6 points] Additional programming constructs.
- Draw a single line under a literal constant on the back of this page.
- Draw a double line under a named constant on the back of this page.
- Draw a triangle around a reserved word on the back of this page.
- Place square brackets, [], around a data type on the back of this page.
- Place parenthesis, (), around a pre-processor directive on the back of this page.
- Draw an arrow pointing to a standard identifier on the back of this page.
- [4 points]getline
- Give the syntax for the getline function.
- Describe the operation of the getline function.
- [4 points] Describe each of the following programming tools:
- [6 points] Comments
- What is a comment?
- Describe the syntax for the two types of comments in c++
- Why does a programmer place comments in a program?
- [10 points] Give the full c++ code for a program which asks the user for their first and last names, then prints the message Hello firstname lastname!, where firstname and lastname are the input supplied by the user.
#include <iostream>
#include <string>
using namespace std;
const string TOP_LINE = "+=+=+=+=+=+=+=+=+";
int main () {
string userDay;
cout << "Enter your favorite day of the week => ";
getline(cin, userDay);
cout < <
cout < TOP_LINE << endl;
cout << "+" << userDay << "+" << endl;
cout < TOP_LINE << endl;
return 0;
}