Activity #1

advertisement
Elizabeth City State University
Spring 2010: CSC 115 Computer Science I
In-class activity #1
Due: Today before Midnight
You can work as individual or only in group of two people but not more than that.
Answers must be typed include names of people, course sections, class time, and current date. For the program, you
must submit the source code (C++ file) and screen capture that show your output.
#’s 1 to 4 should be solved manually. You should not paste the code in C++ project.
1. [16 pts] What is printed by the following program? Suppose the input is: 20
15
#include <iostream>
using namespace std;
int main()
{
const int NUM = 10;
const double x = 20.5;
int a, b;
double z;
char grade;
a = 25;
cout <<"a = " <<a <<endl;
cout <<" Enter two integers : ";
cin >> a >> b;
cout << endl;
cout << " The numbers you entered are "
<<a <<" and " <<b <<endl;
z = x + 2 * a - b;
cout <<"z = " <<z <<endl;
grade = 'A';
cout <<"Your grade is " <<grade <<endl;
a = 2 * NUM + z;
cout << "The value of a = " << a <<endl;
return 0;
}
2. [9 pts] What type of input does the following program require, and in what order does the input need to be
provided?
#include <iostream>
using namespace std;
int main()
{
int x,y;
char ch;
cin >> x;
cin >> ch >> y;
return 0;
}
3.
[22 pts] Suppose x, and y are int variable and ch is a char variable. Consider the following input:
5
25
36
What is value (if any) is assigned to x, y, and ch after each of the each of the following statements
executed? (use the same input for each statement.)
a. cin >> x >> y >> ch;
b. cin >> ch >> x >> y;
c. cin >> x >> ch >> y;
d. cin >> x >> y;
4. [9
pts] given the input 46
A
49
and the C++ code:
int x = 10, y =18;
char z = ‘B’;
cin >> x >> y >> z;
cout << x <<" " <<y << " " <<ch;
What is the output?
5. [44 pts] To make a profit, a local store marks up the prices of its items by a cetarin percentage. Write a
C++ program that reads the original price of the item sold, the percentage of the marked-up price, and the
sales tax rate. The program then outputs the origianl price of the item, the percentage of the mark-up, the
store’s selling price of the item, the sales tax rate, the sales tax, and the final price of the item. ( The final
pice of the item is the selling price plus the sales tax.)
Download