![]() |
CSE 143 Summer 2001Homework #0Due: Electronic submission by 9:30 pm, Wednesday, June 20. Paper receipt due in sections the following day. |
The purpose of this assignment is to help you get oriented to the course and be sure you can compile and run a simple C++ program. It will not be a big factor in your grade, but you should do it anyway to be sure things are working properly. Only the final part will be checked and graded.
The first thing you should do is become familiar with the course's web pages. The web is a primary means of disseminating course information. You are expected to look to the web for answers before you ask the staff, and to check it regularly for updated information.
Check the main web page for the course; follow links that you find there and get a sense of where things are. Be sure to pay attention to anything marked "required reading" - you are responsible for this information.
The newsgroup uwash.class.cse143.bboard is for general discussion about course topics. You should check this regularly. Feel free to contribute to the discussion and post questions, answers, or other course-related notes here.
You should have a UWNetID and regularly read mail sent to the address you've provided to UW. We will send mail to that address if we have an urgent announcement that everyone in the class should read. These messages will also be archived on the CSE 143 web site. Make sure you can find the archive again if you need it!
In order to help us assess your programming knowledge in C, please fill out this on-line survey. This data will be used anonymously to help us learn about your current understanding of C (don't worry, even though it requests your UW Net ID, it is not possible for us to link your identity with your responses). At the end of the survey, make sure you click submit so that the questionnaire is successfully completed.
Next are the programming tools. You are free to use any current standard C++ implementation, but, particularly if you're still new to programming, you may find you're best off if you use the same setup that's installed in the IPL: Microsoft Visual C++ 6.0 on Windows PCs. You'll get better support from the course staff, and this is the system that is used to compile your programs when you turn them in. If you haven't used Visual Studio before, look on the CSE 143 and CSE 142 web pages for tips.
Follow these steps to create a C++ project and a program in Visual
Studio. Start Visual C++. Create a new, empty console application (File >
New... > Win32 console application
); call the project hw0Step4 or
something similar.
Then, create a new
C++ source file named bugs.cpp
. Type in the
following program, exactly as you see it here (but with a
different message if you like):
#include <iostream> using namespace std; int main(void){ cout << "Bugs everywhere!" << endl; return 0; }
Compile and run the program. If you encounter any errors or warnings, fix them. Quit Visual Studio, then start it again to be sure you can resume working on a program. Don't go on to Step 5 until you can do this.
If you normally work in the lab and store your files on a floppy disk, you'll want to configure your Visual C++ project file so it stores Visual Studio's temporary files on the hard drive. This is useful for a couple of reasons: first, programs compile and execute much faster if these larger files are on a hard drive, and second, these files often get too big to fit on a floppy disk, even if you're willing to put up with slow builds. [If you always work on the same computer on the hard drive, you won't need to worry about this.]
You can configure your project to do this as follows. Create a project as before, but be sure to put the project file and source files (.cpp) on a floppy disk. Before compiling the project the first time, change the directory for the temporary files so they are stored on the hard drive instead of the floppy [Project/Settings/Intermediate and Output files -- put the files in a directory like C:\temp]. Compile and run the program. Verify that the temporary files are on the hard drive.
Of course, it may just be simpler to copy your project folder from the floppy disk to the hard drive, then copy the project and source files, but not the temporary files, back to the floppy when you're done. If you do this, be sure to delete the copy on the hard disk once you've copied it to the floppy so it won't be accidentally found and used by someone else.
Here's another programming exercise.
Write a C++ program to convert Fahrenheit temperatures to Celsius. It should repeatedly prompt the user for a temperature in degrees Fahrenheit, and output the corresponding temperature in degrees Celsius. You should use C++ stream I/O (cout and cin; see text, Appendix A), not C's printf and scanf. The conversion is Celsius = (Fahrenheit-32.0) * (5.0/9.0). Here's a sample dialog with the program:
Please enter a temperature in degrees Fahrenheit:
72
72 F = 22.2222 C
Please enter a temperature in degrees Fahrenheit:
110
110 F = 43.3333 C
Please enter a temperature in degrees Fahrenheit:
18.0
18 F = -7.77778 C
You should break the program into two functions. Function fToC()
should have a single parameter of type double and return a result of type
double. The parameter is the Fahrenheit temperature and the result should be the corresponding Celsius temperature. Function main()
should prompt the user for input, read the Fahrenheit temperature, call fToC
to compute the corresponding Celsius value, print the result, and repeat.
You can terminate the program by simply clicking the close box on the console
window; that's good enough for now.
Now comes the new part: place the main function in one
file named main.cpp
, and the other function in a file called fToC.cpp
. Create a
project which includes both .cpp files. Compile and run it.
Debug as necessary. (For help on creating a project, check out our homework
help page. Be sure that the project is a "Win32 Console Application", "empty project".
If you pick something else, you may get some very strange errors.)
Here's an outline for the files:
----- main.cpp ----- #include <iostream> using namespace std; // function prototype for fToC double fToC (double); int main( ) { ... } ----- fToC.cpp ----- // = Celsius temperature equivalent to Farenheit temperature f double fToC (double f) { ... }
The programming projects in this course will normally have a project folder containing the project file and several C++ source files. This is your chance to figure out how to create such a multi-file project and run it.
After completing homework assignments, you must turn them in using your web browser. For this assignment, you should turn in the .cpp files from step 5, above.