CMPSC 201 Programming Assignments

Since one of the main course objectives of CMPSC 201 is to use certain computer programming techniques to solve problems, you will have to complete a number of programs throughout the semester. It is essential that you follow the Programming Process. It is also important that you follow the course Coding Standards when you write each program.

The Programming Process - You must conscientiously follow these steps in order to be successful in writing programs efficiently. Students who do not have the patience to follow the steps WILL have difficulty completing the assignments.

1. Define the problem and understand the given specifications. Create a test plan.
2. Develop an algorithm by writing pseudocode.
3. Code the program by writing it out on paper first.
4. Test and debug the program.
5. Document and maintain the program.

Coding Standards - Hopefully, you will become a better problem-solver throughout this course. However, even if you write programs that follow the given specifications perfectly and work to the degree that they display the proper results, you may miss points if you do not follow the Coding Standards. Read these guidelines thoroughly. If you have any questions, be sure to consult the instructor and your textbook. Take the time to check your program and code thoroughly before submitting it so that you do not lose points for violating these guidelines.

This rubric will be used to grade your programs.


Assignment #1:

Follow the compiler instructions to create your first C++ source file named a1.cpp and execute that file. Type the code below when necessary.

// your name here
// a1.cpp

#include <iostream>
#include <cstdlib>
using namespace std;


int main()
{
      cout << "hello world" << endl;
      system("PAUSE");

      return 0;
}// end of main

Compile and debug the program if necessary. Execute the program. Print the source file by clicking the Visual C++ File/Print... menu command and submit it by the due date.

You must also upload copies of the source file (.cpp) and executable file (.exe) to the appropriate drop box in Angel by the beginning of the class period on the due date. You will lose points if any file is named incorrectly.


Assignment #2:

Write a C++ program that allows the user to input values for the major radius and then the minor radius of an ellipse. The program must then display the circumference of the ellipse. The outputted value must be displayed rounded to the nearest whole number.

Save the source code file as a2.cpp. You must pseudocode this assignment before you begin to write the code or type the code into C++. Write a test plan as well before you write out or type the code. You must choose the proper variable data types. Include user-friendly, explanatory input prompt messages so that the user knows exactly what to type as inputs. You must follow the Coding Standards so that it is easy to read your program and so that others can understand your code. You must add a system("PAUSE"); statement just before your return 0; statement and add #include <cstdlib> at the top of your program just as you did in Assignment #1.

You must add the line    system("PAUSE");    right before     return 0;      in order to receive any credit for this assignment.

Preconditions:

You must turn in the hardcopy printout of your source code file named a2.cpp at the beginning of the class on the due date. Staple multiple pages together, if applicable.

You must also upload copies of the source file (named a2.cpp) and the executable file (named a2.exe) to the appropriate drop box in Angel by the beginning of the class period on the due date.


Assignment #3:

Write a C++ program that finds the closest integer approximate root of a linear equation that is known to contain a root between x = -100 and x = 100. The user must be prompted to input the m and b terms (in that order) of the linear equation y = mx + b. The program must display the rounded integer approximate root and the number of loop iterations that were used to find the approximate root. For example, if the real root is 8.5, then the outputted integer should be 9. If the real root is -8.5, then the outputted integer should be -9. You must use a loop in this program that inspects possible integer roots starting at x = -100. Do NOT set y equal to zero and solve the equation for x with assignment statements.

Save the source code file as a3.cpp. You must pseudocode this assignment before you begin to write the code or type the code into C++. Write a test plan as well before you write out or type the code. You must choose the proper variable data types. You must follow the Coding Standards so that it is easy to read your program and so that others can understand your code. You must add a system("PAUSE"); statement just before your return 0; statement and add #include <cstdlib> at the top of your program just as you did in Assignment #1.

You must add the line    system("PAUSE");    right before     return 0;      in order to receive any credit for this assignment.

Preconditions:

You must turn in the hardcopy printout of your source code file named a3.cpp at the beginning of the class on the due date. Staple multiple pages together, if applicable.

You must also upload copies of the source file (named a3.cpp) and the executable file (named a3.exe) to the appropriate drop box in Angel (look under the Lessons tab) by the beginning of the class period on the due date.


Assignment #4:

Write a C++ program that uses the multiple-application Simpson's 1/3 Rule to compute the area under the curve formed by an equation of the form f(x) = Ax^3 + Bx^2 + Cx + D. The ^ symbol is used here to show exponentiation. The floating-point values for A, B, C, and D as well as the values for n (number of segments), a (lower boundary of integration), and b (upper boundary of integration) must be read from the file C:/Temp/a4data.txt in that exact order. The output should be displayed using fixed notation with the maximum level of precision as possible. Use functions where appropriate.

Save the source code file as a4.cpp. You should pseudocode this assignment before you begin to write the code or type the code into C++. You should also write a test plan as well before you write out or type the code. You must choose the proper variable data types and follow the Coding Standards so that it is easy to read your program and so that others can understand your code. You must add a system("PAUSE"); statement just before your return 0; statement and add #include <cstdlib> at the top of your program just as you did in Assignment #1.

You must add the line    system("PAUSE");    right before     return 0;      in order to receive any credit for this assignment.

Preconditions:

You must turn in the hardcopy printout of your source code file named a4.cpp at the beginning of the class on the due date. Staple multiple pages together, if applicable.

You must also upload copies of the source file (named a4.cpp) and the executable file (named a4.exe) to the appropriate drop box in Angel by the beginning of the class period on the due date.