2018
|
|
For this week, here's the plan, Dan…
C
|
First things first: First we need to cover the basics, since fundamentals are critical to success in anything!
|
|
There is no assigned textbook for this course. There are a number of books that address the concepts we will study, but they are all very expensive. I have a bunch of them in my office, and you are free to come check them out. In fact, you are encouraged to do so! While these immortal tomes do collect the information all in once place for convenience, you can find all the same information on the Internet if you just apply yourself a bit. In addition, here are some very useful and informative links to related material:
MinGWwhich you can install on Windows to get a UNIX/Linux-like command line environment including GCC.
Cprogramming main page
You can also get a free downloadable textbook through the library called Programming with
64-Bit ARM Assembly Language
. Log in to the Hannon Library website using your LMU
credentials, search for that title, and download the book!
The following items will be tools you need to do the work in this course:
|
|
Integrated Development Environmentsor
IDEs; examples include the venerable Eclipse IDE from this site, and NetBeans, which is direct from Oracle at this location. Another one that you have probably already seen [if you haven't installed it already] is VS-Code.
stockor customize to your heart's content. Some allow you to add links to compile and even run your code. The IDEs have the advantage of compiling as you go, which shows you the error of your ways with nearly every keypress. All have ability to display the line numbers for the code, which is REALLY handy for collaborative debugging. Some people [like me] find the fact that IDE's correct things problematic. I'll talk about that in class.
GitHub Desktopwhich gives you the ability to mirror your remote repository directly from your laptop. You can get a copy of that tool at this location. Finally, you can use the command line if you have installed the
Git Bashtool. This application allows you to use typed commands to do the same thing that GitHub desktop does using a GUI.
…Just to make sure we're all adults…
In years past when classes were smaller, we had the time to go through the dreaded pariah of all
classes and students, the
tell-the-professor-all-about-me
excercise, which was guaranteed to have all students
shifting uneasily in your seats! However, with larger classes, we don't have time to do that,
so I'll just ask for your names and pronunciation as I go through the roster to make sure
everyone is accounted for.
Homework assignments and in-class exercises will be done in groups. For section one which has 20 folks the groups will comprise two people. For section two which has 19 students, the groups will comprise two people with one group having three. We will get this together during the first two weeks of class if not earlier.
If you already have someone you want to work with, that is fine. Let the professor know your names and you will be put into a group together.
Otherwise, the professor will put you into a group.
Groups will be the same throughout the semester.
Homework assignments for this class must be done in groups.
For each assignment, you and your partner[s] turn in ONE copy of the assignment. Assignments are of
mixed types, with exercises consisting of both programming projects and short answer questions. As
many of you may have heard, I'm a big believer in fostering critical thinking
skills, so there
will be questions that are intended to make you think about what you are doing in
various respects like morals, ethics, and decomposition of problem statements in addition to
programming tasks.
All homework must be submitted into a GitHub repository. Please make an account if you don't already have one, and make a repository for this class. NOTE: because the assignments will be done in groups, you will need a single shared repository for your group. If you WANT to make individual accounts you are welcome to do so, but please be sure that I know which account will be the one you are using for the submissions. Note that means ONLY one account for submissions for the ENTIRE SEMESTER! I don't want to go chasing around through multiple repos to find your submissions.
Please name your repo using the phrase "CMSI-2210_" in the name, followed by the last names of
the team members, according to the following specification: use uppercase letters for the
CMSI
, then a dash, then the numbers 2210
, then an underscore, followed by the last names
of the team members in alphabetical order. For example, if Anais Nin, Talia Shire, and Pablo Picasso
are in a group, name your repo
.
CMSI-2210_NinPicassoShire
Once that is accomplished, under your repository please generate the following FOLDER STRUCTURE [which I will demonstrate in class]:
By the way, this is VERY EASY to do if you use GitHub Desktop since you can maintain a local copy of your repository on your laptop computer and simply commit using the tool. You can then access that local copy using the command line/terminal window which gives you the power to do almost everything at one time with maybe three commands. Again, I'll show this in class.
I will be using this folder structure to perform the evaluations of your work. I use the GitHub desktop on my Windows machine to duplicate [clone] your repository to my local computer for doing those evaluations, and I have several scripts that I set up to facilitate compiling/assembling and running your programs. Any deviation from the above structure means my scripts will not work with your submissions, and you will NOT earn any credit.
Additionally, CODE THAT DOES NOT COMPILE OR ASSEMBLE WILL NOT BE EVALUATED.
PERIOD.
FULL.
STOP.
The time for submitting code with compile errors is past since
you have been through CMSI 185/186/1010. Make sure your code compiles/assembles FROM THE
COMMAND LINE/TERMINAL WINDOW before you turn it in. I will be demonstrating how to do that in
class in case you are unfamiliar.
REMEMBER: I use the command line/terminal window for compiling/assembling and running your programs. If you are using an IDE like NetBeans, VS-Code, or Eclipse, be sure your program can be successfully compiled/assembled from the REAL command line or terminal window, and that it runs that way as well. It's an extra step for some of you, yes, but this operation/activity reflects the real world of software development – just because it works for you in VSCode doesn't mean that the USERS who run your code will be running it from VSCode, if they even HAVE VSCode.
|
You will be learning the You will also be learning assembly language during this course. Again, you won't become an expert, but you WILL get experience with how assembly lets you access the lowest levels of processor operations, which s a fundamental knowledge of how programs and applications work. Many students absolutely HATE assembly, at least at first, because it can be difficult to get programs to work properly since the concepts are so low-level. However, if you apply yourself and take the challenge, assembly can actually be fun, because you have full control of the computer and can make it do all sorts of things that are much more difficult [even impossible!] in any other language. |
|
Since there is not a textbook, homework assignments will be taken from other places. Most, if not all, of the programming assignments can be found, with their corresponding [potential] solutions, on the Internet. However, as clearly stated on the syllabus page, copying code from the Internet is plagiarism, unless you cite where you got it! If you download a solution to turn in, put a comment in the code in a header at the top of the file that says where it came from. You had also better be able to tell me HOW IT WORKS AND WHY IT'S A GOOD SOLUTION so that I can assess if you really understand it. Deviation from this policy will earn you a grade of zero on the assignment.
C
Practically since the time it was invented, people have hated programming in this language. It can be very tricky to use, since even though it is considered a 'higher level' language, it is only one step removed from assembly language. This makes it very fast, and speed is essential to success in many applications such as embedded sensor systems, avionics, automobiles, and operating systems. However, the idea of memory allocation, pointers, structures, and other such concepts are very confusing at first.
C
is a compiled language, but it's not compiled like Java. As you know, when you make a Java
program, you compile it to byte code, then you start the JVM to run the program. The JVM
handles all the access to operating system functions for you. However, with C
you must handle
such things yourself. There is no virtual machine middleware, your program is compiled directly to
binary that the computer can execute, and is linked with a set of libraries that handle a lot of the
low-level operating system calls for you.
First things first: we will be using the command line! There is a brief list of common commands on the course web site at this link. I recommend that you read it and get familiar with these commands. Second, you are free to use an IDE to develop your code if you wish; but be aware that when I evaluate your work, I will be using the command line! Any code that doesn't work when I type in the command manually will not be given a grade.
The definitive book on the C
language is still the K & R
book written by Kernighan and
Ritchie sometime in the last century. In some ways, the language has changed a lot. In other basic ways,
it is pretty much the same as it always was. It is those same parts we'll be using. If you can find a
copy of the book you might snag a copy for yourself. For those who are looking to get into embedded
systems programming it will be WAY more than just a doorstop
or paperweight
.
The ISBN is
978-0131103627.
Traditionally, the first program in any language is the hello world program. Actually, this probably started with
C
, since it is the first thing in the book. The program looks like this:
#include <stdio.h>
int main( int argc, char * argv[] ) {
printf( "\n\n Hello, world!\n\n" );
}
This should look very Java-esque
to you, and for good reason. In fact, Java syntax [according
to the Nutshell book] was initially modeled on the C
language. I'll pick this program apart
during class. This is the first program you will use to verify that your development environment is
set up and working properly.
Much of the language consists of standard libraries. There are quite a few of them, but you will
most often use the stdio, stdlib, string, and a few others. We'll see them during the course. The
point here, though, is to notice the #include
line at the top of the file [which is pronounced
pound include
]. Here is a
link to a very good [reference] website for learning all about the C
standard library.
C
is statically typed, just like Java. You must declare the variables' types, and they must
remain that type for the duration of the program or module [scope-based]. There are LOTS of types,
and there is type coersion and casting as you'd expect. Vanilla C
doesn't have objects, and
that's another reason people don't like it; instead you have structs
or structures, which
allow you to define aggregated user-defined data types, that are like an object, but are
NOT an object. There are 'strings', but they are treated as sequences [arrays] of characters and
always must end with a null
character, which in this language is the sequence \0
. Sometimes
it is put on the end of the string automatically by a function, and sometimes you have to add it yourself.
Another thing which gives people fits is variable addressing
, also known as pointers
. This
concept allows the programmer to de-reference
a variable. We'll see how all this works as we go
along.
One of the first things we'll learn about C
programming is that there are LOTS of ways to make
the programs and make them correctly. To start with, let's take a look at an old standby, a program
to convert Fahrenheit to Celsius. Here is what it looks like in JavaScript:
let f = parseFloat( prompt( "Enter a temperature in degrees Fahrenheit: " ))
alert( f + " degrees F is " + (((f - 32) * 5) / 9) + " degrees C." );
Note that it's two simple lines. By the way, you can run JavaScript code in this window. That makes it easy to test out simple JavaScript code, which we'll do in class.
In Python it looks like this:
f = float( input( "Enter a temperature in degrees Fahrenheit: " ) )
print( f, "degrees F is ", (((f - 32) * 5) / 9), " degrees C" )
In Java it looks like this:
import java.util.Scanner;
class CtoFconverter {
public static void main( String args[] ) {
System.out.println( "Enter a temperature in degrees Fahrenheit: ");
Scanner myInput = new Scanner( System.in );
double degreesF = Double.parseDouble(myInput.nextLine());
System.out.println( degreesF + " degrees F is " + (((degreesF - 32.0) * 5.0) / 9.0) + " degrees C." );
}
}
[Note to self: several things about this code ⇑ to the class.]
Now, here it is in C
:
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char * argv[] ) {
double degreesf;
char input[25];
printf( "Enter a temperature in degrees Fahrenheit: " );
degreesF = atof( gets( input ) );
printf( "%10.3f degrees F is %10.3f degrees C. ", degreesF, (((degreesF - 32.0) * 5.0) / 9.0) );
exit( 0 );
}
[Note to self: several things about this code ⇑ to the class.]
As far as commanding, controlling, or operating a computer goes,
ANYTHING you can do in
a GUI, you can do from the command line!
Sometimes this seems a bit counter-intuitive, because we have all become so used to using the Graphical User Interface [GUI] that we don't even stop to think about it. However, back in the days BEFORE there WAS a GUI, there was ONLY the command line, and we got along just fine! [An interesting read about this by author Neal Stephenson of Snow Crash fame is available for download as either a zip file for Windows or a stuffit file for Mac at this link.]
The first thing to realize is there are two different versions of the command line, one for Windows and one for Mac, and they have different commands to do the same operations. We'll see how this goes in a few minutes.
The second thing to realize is, there are multiple versions of the command line based on which version of
UNIX/Linux you are using. For most Mac users, that will be either the bash
shell or the
zsh
shell, which may be familiar to many of you. The word shell
is applied to the
Command Line Interpreter
, also known as the CLI
, which is the part of the Operating System
[O/S] that interprets typed user commands on the command line.
Some of the VERY basic commands are listed on this page of the web site so that you can have easy access to them. A simple Internet search will turn up hundreds or thousands of help pages as well, no matter what platform you are using.
[move along to demonstrate some common commands in Windows. Don't forget to bring in a Mac if possible, or borrow one from a student to plug in for a terminal window demonstration.]
The purpose of this assignment is to make sure that you have all the parts set up for doing the work that will be part of this course. There are two parts: in part one you will work in class to get the coding environment set up and verify that it works; in part two you will modify the initial code from this classwork exercise
gccand press
ENTER. If you get an error message that says:
gccprogram but you didn't give it a source file to work with.
sayhello.c in a directory of your choosing by whatever
method you are comfortable with.
Hello, World!to the console using
printf(); you'll need to include the stdio.h header file. Use the code
shown in the previous example for F to C conversions as a model.
gcc sayhello.c -o sayhello
ON MAC —→ ./sayhello
ON WINDOWS —→ sayhello
sayhello.c file to your repo.
I wanted to give you a heads-up on the homework assignments that you will be doing this semester. They are all available from the syllabus page, but just to make sure… Assignment number one is due this week, and assignment number two is due on Wednesday/Thursday of week three.
Also note that homework #1 is an extended version of your in-class assignment for this week. You should end up with a copy of both the in-class portion and the homework portion in your 'homework01' folder in your repository along with the expanded version of the program there. You only need to submit one copy of each thing for your group, and I won't actually be looking at them until week three. This is to give you time for your groups to be composed.
That's probably enough for the first week. Be sure to check out the links to the related materials that
are listed on the class links page. Also, don't forget the project page!
I hear, and I forget.
I see, and I remember.
I do, and I
understand.
— Ancient Chinese Proverb