Assigned: | Wednesday, August 21 |
Due: | Wednesday, September 4, 11:59pm |
Points: | 50 |
The purpose of this assignment is to ensure that you know how to log into Linux, compile and run a program, and submit your solution.
You will submit two files, assn0.cpp and answer.txt.
Log into Linux. Start a terminal. Create a directory (folder) to hold your CSCI 2530 submissions, and a subdirectory of that to hold assignment 0.
Download Makefile into your new directory. Be sure that the file is called Makefile. Its name is 8 letters long. There is no extension.
Open a text editor. Create a new document called assn0.cpp and copy the following program into it. (Do not copy it by hand! Just copy and paste.)
// CSCI 2530 // Assignment: 0 // Author: Karl Abrahamson // File: assn0.cpp // Tab stops: none // This program shows the greatest common divisor // of two numbers that are read from the user. #include <cstdio> using namespace std; //=========================================== // gcd //=========================================== // gcd(a,b) returns the greatest common // divisor of a and b. //=========================================== long gcd(long a, long b) { if(a == 0) { return b; } else { return gcd(b % a, a); } } //=========================================== // main //=========================================== int main() { long a, b; printf("gcd of which two numbers? "); if(scanf("%li%li", &a, &b) == 2) { printf("The gcd of %li and %li is %li.\n", a, b, gcd(a,b)); } return 0; } |
Compile and run the program. The Makefile lets you use the following two commands.
When you run assn0, the program will ask you for two numbers. Copy
6456477721591 6456492967333into the terminal and press the enter key. Record the answer and save it into a file called answer.txt. (Just open another document in the text editor.)
Normally, you would not submit my work as your own, but that is okay in this assignment, which is just to get you some experience to using Linux. In the directory that contains your work, run command
~abrahamsonk/2530/bin/submit 0 assn0.cpp answer.txtYou should get a reply that the submission was successful. Command
~abrahamsonk/2530/bin/submit 0lists the names of the files that you have submitted for assignment 0.