Corning Community College
C/C++ Programming
Task 2: Variables and Equations
~~TOC~~
To utilize variables and to create equations to solve problems.
In class, we started writing some simple programs to play with input/output and manipulate variables.
What we're going to do is provide an opportunity to put those skills to use writing some programs.
Write a program that contains the following variables (choose the best fitting type for each variable):
Have your program prompt the user for input (for each of the “score” variables), assume the user will put in a value in the range of 0-100.
Once you get through all 8 scores (score0 through score7), I want you to do the following:
Be sure to save a copy of your working source code as task2-average.c in your ~/src/submit/ directory, and add/commit it to your repository.
Write a program that contains the following variables (choose the best fitting type for each variable):
Have your program prompt and get input for the starting x y and ending x y of a line.
Once you get the coordinates, I want you to do the following:
Be sure to save a copy of your working source code as task2-slope.c in your ~/src/submit/ directory, and add/commit it to your repository.
Just to review the compilation/execution process for working with your source code, if we had a file, hello.c, that we wished to compile to a binary called hello, we'd first want to compile the code, as follows:
lab46:~/src/cprog$ gcc -o hello hello.c lab46:~/src/cprog$
Assuming there are no syntax errors or warnings, and everything compiled correctly, you should just get your prompt back. In the event of problems, the compiler will be sure to tell you about them.
Conceptually, the arrangement is as follows:
gcc -o BINARY_FILE SOURCE_FILE
The BINARY_FILE comes immediately after the -o, and the SOURCE_FILE, must never immediately follow a -o. It can precede, and such is perfectly valid (especially if you feel that way more intuitive).
To execute your binary, we need to specify a path to it, so we use ./, which basically says “in the current directory”:
lab46:~/src/cprog$ ./hello Hello, World! lab46:~/src/cprog$
As you write your code, hopefully you've developed the good habit of storing all your programs in your ~/src/cprog directory (and have added/committed them to your repository).
But, in order to complete your tasks, you've been requested to place it in your ~/src/submit directory instead.
What to do?!
We'll simply make a copy of your code! Assuming we're working with a source file called myprog.c in our ~/src/cprog directory, we'll copy it into ~/src/submit/ and give it a name of: taskX.c
To do that we use the cp command, and run it as follows:
lab46:~/src/cprog$ cp myprog.c ~/src/submit/taskX.c lab46:~/src/cprog$
We can then hop over to our submit directory and add/commit it:
lab46:~/src/cprog$ cd ~/src/submit lab46:~/src/submit$ ls contact.info taskU.c taskV.c taskW.c taskX.c lab46:~/src/submit$ svn add taskX.c Added taskX.c lab46:~/src/submit$ svn commit -m "added taskX.c to the submit directory" ...
All questions in this assignment require an action or response. Please organize your responses into an easily readable format and submit the final results to your instructor per the appropriate methods.
Your assignment is expected to be performed and submitted in a clear and organized fashion- messy or unorganized assignments may have points deducted. Be sure to adhere to the submission policy.
When complete, questions requiring a response can be electronically submit using the following form:
<html><center><a href=“http://lab46.corning-cc.edu/haas/content/cprog/submit.php?task2”>http://lab46.corning-cc.edu/haas/content/cprog/submit.php?task2</a></center></html>
Additionally, the successful results of the following actions will be considered for evaluation:
As always, the class mailing list and class IRC channel are available for assistance, but not answers.