### COSC 071: Computer Science I

Project 1
Fall 2003

Specific solution and algorithm (written) due: Sep 23 in class
C++ Implementation (electronic) due: Sep 29 @ 5 PM
5 points

The Dell interns know they're on shaky ground, so they've asked you to help their image by writing some software that might make Michael happy.

They need software to help them configure and price computer systems. The base price for systems is all the same, but customers can choose from a variety of options, including a faster processor, more memory, and a different operating system. If the buyer is from Texas, where Dell is located, then sales tax is applicable. There are also shipping costs for all systems.

The base system costs \$1,699. It comes with an Intel 2.8 Ghz Pentium 4 (P4) processor, 512 MB of RAM, a 17" flat-screen Monitor, a video card, an 80 GB hard drive, and Windows XP Home Edition. Customers can upgrade to a 3 Ghz P4 for \$170 and to a 3.2 Ghz P4 for \$430. To upgrade the memory, they can spend \$190 and get 1 GB of RAM or \$650 and get 2 GB. If they select Redhat Linux 9.0, then it reduces the total cost by \$190.

Sales tax in Texas is 4.5%, and shipping to any location in the US is \$25.00.

The written portion of this assignment consists of two parts. First, solve the problem using the data for the fifth configuration below. Second, based on the steps taken to derive this solution, develop an algorithm, the general solution, using the five statements below, which are similar to those from HW1:

1. input
2. output
3. calculate
4. if condition, then statement
5. if condition, then statement; otherwise, statement
If you need to group multiple statements together, say in an if statement, use
begin
statement
...
statement
end
If you prefer, you may express your algorithm as a flowchart.

Naturally, the implementation portion of the assignment involves implementing your algorithm as a C++ program. Make sure it works for the five data sets below.

Avoid using literals in your program by declaring constants for values that do not change during program execution, like the base price of the computer. Declare all constants and variables at the top of the main function. Store quantities using the appropriate data type, and if needed, convert between ints and doubles using static_cast.

The program should guide the user through the configuration process, displaying a running total. After the user has entered all the pertinent data, the program should produce a list of the computer's components and the associated costs.

For example, if someone in Texas wanted a computer with 2 GB of memory, then the program run might look like the following:

```gusun% a.out

Base Computer System:
2.8 Ghz. Pentium 4 Processor
512 MB of RAM
80 GB hard drive
Video card
17" flat-screen monitor
Windows XP Home Edition

Cost: \$1699.00

Operating system option:
0 - Windows XP Home Edition
1 - Redhat Linux 9.0, subtract \$190.00
Choice (0-1): 0

1 - 3.0 Ghz Pentium 4 Processor, add \$170.00
2 - 3.2 Ghz Pentium 4 Processor, add \$430.00
Choice (0-2): 0

1 - 1 GB RAM, add \$190.00
2 - 2 GB RAM, add \$650.00
Choice (0-2): 2

Texas residents must add 4.50% sales tax.
Are you a Texas resident (y/n)? y

System cost with options: \$2349.00
Sales tax for TX residency: \$105.70
Shipping: \$25.00
Total cost: \$2479.70

Thanks for choosing Dell!
```

Run and test your program using the following five configurations:

 Configuration CPU Memory OS TX Resident? 1 2.8 Ghz 512 MB XP Y 2 3.2 Ghz 2 GB Redhat N 3 3.0 Ghz 1 GB XP N 4 2.8 Ghz 512 MB Redhat N 5 3.0 Ghz 1 GB Redhat Y

Hint: Once you've expressed your solution as a C++ program, don't just sit down and type it all in like a history paper. I'll talk more about stepwise refinement and incremental development in class, but the idea is develop and enter the program in pieces and build it incrementally.

To do this for this project, start with an empty main function. Then write a program that prints the configuration of the base system and its total price with no options (i.e., with just shipping charges). Then modify the program to handle a customer who is a Texas resident. Then modify it to handle the choice of operating system. Proceed in this fashion until the program is finished. Notice that you'll always have a program that does something, but at each step, you're increasing its functionality.

Even within each step, you can break things down further. For instance, to write the logic for handling Texas residents, you'll need to declare an object, use it in an input statement, but then just print its value. Compile and run the program. If everything works as expected, then remove the cout statement and write if statement that uses the object. Put a cout statement in the if statement, compile, and see if it works. Continue in this fashion until you've entered your program. You should always have a program that compiles and executes. It may not do everything, but it will always compile and execute.

This approach minimizes errors and helps manage the complexity of software development. If you start each step with a working program and you add a few lines of code, if you make a mistake, then it mostly likely involves the last few lines you typed. If you start by entering your 300-line program and hit compile, you'll be overwhelmed by the number of compiler errors. Even seasoned programmers don't do this.

Instructions for Electronic Submission: At the top of the file containing your source code (i.e., the file containing the C++ instructions), place the following header comment, with the appropriate modifications:

```//
// Project 1
// ID: <GoCard ID>
// Instructor: Maloof
// TA: <TA's name>
// COSC 071
//
// In accordance with the class policies and Georgetown's Honor Code,
// I certify that, with the exceptions of the lecture notes and those
// items noted below, I have neither given nor received any assistance
// on this project.
//
//
```

Although you may use any C++ compiler to develop your program, it must run under UNIX and must compile using GNU g++. When you are ready to submit your program for grading, if necessary, use SSHWin to transfer your source file from your PC to gusun. Use SSHWin to logon to gusun, and use pine to e-mail it to your TA. Use your netid and the suffix ``.cc'' as the subject.

```gusun% pine
```

When the menu appears, select the item for composing e-mail. Assume that your netid is ab123, the name of your source file is proj1.cpp, and your TA's e-mail address is ``imagoodtamaloof@cs''.

Type your TA's e-mail address in the To field, and type your netid with the .cc suffix in the Subject field (no spaces before or after). Move the cursor down into the MESSAGE TEXT screen, and type the ^R (Ctrl-R) command. Pine will ask for a file name (e.g., proj1.cpp), which it will then load as your message text. At this point, your screen should look something like the following:

Finally, type ^X (Ctrl-X) to send the e-mail to your TA.

IMPORTANT: Do not send your source code as an attachment. Do not use a mail client other than pine.

If you need to include a message to you TA about your submission, then type the message as a comment in the program.

Once you've submitted your project, it is important to keep an electronic copy on a university machine (e.g., gusun or cssun) that preserves the modification date and time. If we lose your project or the e-mail system breaks, then we will need to look at the modification date and time of your project to ensure that you submitted it before it was due.

The TAs who will be grading your projects this semester are listed on the main page. You must e-mail your project before 5 PM on the due date.