cse220-s09-p03-rubric

cse220-s09-p03-rubric - CSE220 Programming for Computer...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE220 Programming for Computer Engineering Lab Project 3: 24 Points Spring 2009 ~ Burger ~ Dept. of CS & Engineering ~ Arizona State University Page 1 You may work in pairs with a partner on this lab project if you wish or you may work alone . If you work with a partner, only hand in one lab report with both of your names on it; you will each earn the same number of points. The deadline for this lab project is 4:00am on Wed 25 Feb 2009. Consult the online syllabus for the late and academic integrity policies. Lab Project Objectives 1. To learn how to use GNU make to build a multifile C project. 2. To learn how header files are used in C to provide linkage between source code files. 3. To learn how to break a larger C source code file up into smaller individual source code files. 4. To learn how to compile a C file with no optimization and with debugging information. 5. To learn how to use gdb to step through code, print variables, set breakpoints, and examine memory. This project is written assuming you are using an account on research.asu.edu which is running RedHat GNU/Linux. You may also use the GNU/Linux machines in the Brickyard Engineering Computer Lab which are running CentOS ( http://www.centos.org ), or your own home computer with whichever GNU/Linux distribution you happen to have installed. Exercise 1: Using GNU Make 1. Log in to the Linux system you are using and start a Bash terminal. Make a subdirectory named cse220-s09-p03 . Make this sub- directory your current directory. 2. Creating a multi-source code file project. Using VI or some other text editor, enter the code for these C source code files exactly as it appears (there is an intentional bug planted in this code that you will fix in the next exercise; if you spot it now, do not cor- rect it). main.c #include <stdio.h> #include "get.h" #include "calc.h" int main() { int n = getint("Enter the value of n: "); calc(n); return 0; } calc.h #ifndef __CALC_H__ #define __CALC_H__ extern void calc(int); #endif calc.c #include <stdio.h> #include "sqr.h" #include "cube.h" void calc(int x) { fprintf(stdout, "%d ^ 2 = %d\n", x, sqr(x)); fprintf(stdout, "%d ^ 3 = %d\n", x, cube(x)); } get.h #ifndef __GET_H__ #define __GET_H__ extern int getint(char *); #endif get.c #include <stdio.h> int getint(char *prompt) { int n; fprintf(stdout, "%s", prompt); fscanf(stdin, "%d", n); return n; } sqr.h #ifndef __SQR_H__ #define __SQR_H__ extern int sqr(int); #endif sqr.c int sqr(int x) { return x * x; } cube.h #ifndef __CUBE_H__ #define __CUBE_H__ extern int cube(int); #endif cube.c int cube(int a) { return a * a * a; } 3. Building the project the hard way. To build this project, we can compile all of the files individually using the GNU C compiler commands. Do this, ~/cse220-s09-p03$ gcc –O0 –g –c main.c compiles main.c and produces main.o ~/cse220-s09-p03$ gcc –O0 –g –c get.c compiles get.c and produces get.o ~/cse220-s09-p03$ gcc –O0 –g –c calc.c compiles calc.c and produces calc.o ~/cse220-s09-p03$
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/02/2010 for the course COMPUTER cse 220 taught by Professor Kevinburger during the Spring '10 term at ASU.

Page1 / 6

cse220-s09-p03-rubric - CSE220 Programming for Computer...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online