



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: DATA STRUCTURES; Subject: Computer Science; University: Rensselaer Polytechnic Institute; Term: Unknown 1989;
Typology: Assignments
1 / 6
This page cannot be seen from the preview
Don't miss anything!




This two-part homework explores the background and review material cov- ered in Lectures 1 and 2. Part 1 is a set of short problems, similar to problems that might appear on a test. Part 2 is a short programming problem. These problems are not particularly difficult. Students who feel uncomfortable about their programming background should view this as an opportunity to gauge their current skills. Programming assignments will become more challenging quickly, so if this one is not relatively easy, you should work hard to practice and catch up. Solutions to the problems in Part 1 must be turned in during class on Fri- day, January 28. Printouts and hand-written solutions are both acceptable. Electronic submissions will NOT be accepted, and late homework (for Part 1) will NOT be accepted. Put your name and lab section number on the top of the first page. Solutions to the programming problem in Part 2 are due electronically by 11:59:59pm on Thursday, January 27th. The standard rules about late homework submissions (see the course syllabus) apply. See below for updated electronic submssion instructions.
#include
void stats_calculation( float values[], int & n, float & max_value, float min_value, float & avg ) { // Find the average value float sum = values[0]; for ( int i=0; i<n; ++i ) sum += values[n]; avg /= n;
// Find the maximum and minimum values. min_value = values[n-1], max_value = values[n-1]; while ( n > 0 )
--n; if ( values[n] > max_value ) max_value = values[n]; else if ( values[n] < min_value ) min_value = values[n]; } }
int main() { // Initialize an array in order to test the function. The size of // the array (6) is automatically determined from the number of // values in the list. float a[] = { 12.3, 15.4, 1.5, 7.8, 2.3, 8.9 }; int size = 6; float min_value = 0, max_value = 0, average = 0;
stats_calculation( a, size, max_value, min_value, average );
cout << "Here are the values: "; for ( int i=0; i<size; ++i ) cout << a[i] << " "; cout << ’\n’; cout << "average = " << average << ’\n’ << "max = " << max_value << ’\n’ << "min = " << min_value << ’\n’; return 0; }
While it is clearly possible for you to create a program file containing this code and then compile and execute the program, you will not have the luxury of doing this on a test. You should practice by studying the code carefully yourself first and trying to determine the answers. This is a good skill to develop.
#include
int main() { int x=5, y=4; float a[3] = {1.0, 2.0, 3.0};
if ( x > y ) {
Write a program that performs a simple version of income tax calculation for a set of individuals. Each individual is represented by a single line of input containing two integers and a float. The first integer is the person’s tax id number, the second is the number of dependents, and the third is person’s earned income this year. Before reading the individuals, your program must read a single integer giving the number of individuals for whom to calculate taxes. This number will be at most 100. The tax owed by an individual is calculated by first subtracting the $ times the number of dependents from the earned income. If this reduces the income below 0, no tax is owed. Otherwise, the tax calculation is
For example, if a person with id 12345 has 3 dependents and earned $37,500, the subtraction for dependents reduces this amount to $30,000, and the tax calculation yields
As another example, if a person with id 9999 has 2 dependent and earned $95,000, then the subtraction for dependents reduces this amount to $90,000, and the tax calculation yields
After reading all of the input the program should calculate all the taxes, output each tax id and the amount owed (each individual on a separate line), and then output the tax ids of individuals who owe no tax and the ids of individuals who owe at least $20,000.
Given the input
5 43231 2 27000 12324 3 7000 54989 0 50000 37434 4 12500 34763 3 85000
the output of the program should be
43231 owes $ 12324 owes $
54989 owes $ 37434 owes $ 34763 owes $ These individuals owe no taxes: 12324 No individuals owe at least $
If instead the input is
4 12324 3 70000 54989 2 500000 37434 4 77500 34763 3 185000
then the output should be
12324 owes $ 54989 owes $ 37434 owes $ 34763 owes $ No individuals owe $ These individuals owe at least $20000: 54989 34763
The output from your program should be as close to this as possible.
(These instructions, which are also posted on the course web site, differ slightly from what was indicated in the homework guidelines distributed on the first day of class.) Submit your program in a single file. For Homework 1, you should submit your program in a single .cpp file. For other assignments, if you have more than one source file, you will need to zip them into a single .zip file. Use your RPI login/password to access the following web site:
https://cgi.cs.rpi.edu/submit/submit.html?course=cs