Computer Science 2530
Spring 2020
Programming Assignment 0

Assigned: Wednesday, January 15
Due: Wednesday, January 22, 11:59pm
Points: 50

Table of Contents

  1. Purpose of this assignment
  2. What you will submit
  3. The assignment
  4. Submitting your work

Purpose of This Assignment

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.


What You Will Submit

You will submit two files, assn0.cpp and answer.txt.


The Assignment

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 for assignment 0. 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.

make
Compile assn0.cpp and create machine language file assn0.
make run
Run assn0.

When you run assn0, the program will ask you for two numbers. Copy

  6456477721591 6456492967333
into 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.)


Submitting Your Work

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.txt

You should get a reply that the submission was successful. If you do not get such a reply, assume that something is wrong. If you added this course late, your name might not be in the course database.

Command

  ~abrahamsonk/2530/bin/submit 0
lists the names of the files that you have submitted for assignment 0.

See submitting assignments.