In: Computer Science
This is an assignment done using the terminal of linux.
In this assignment, you will
• use make to modify a c++ program and
• gdb a debugging tool.
Part 1
From the course website (or the departmental dropbox) download the program source files for the project myname.
Part 2: myname program (5 points)
1. Using your favorite text editor, modify the source code to print out your name instead of mine when the binary file is executed. Hint: YOU ARE NOT ”THOMAS THE TANK ENGINE”
2. Modify the makefile to include a rule that creates a backup of the source files, makefile, and readme in an archive directory in your home directory structure.
Submit a compressed, archived tar file [yourUserID].assignment4_1.tar.[Z,gz] with your modified source code.
3. Use the gdb debugger to step through the program. Check to ensure the Makefile is modified to allow for debugging. Submit a text file [yourUserID].assignment4_2.txt containing the gdb output for the following sequence of commands:
gdb myname
start
step [issue this command until you get the “program exited normally” message]
quit
Submission This time, there should be two files that you are uploading
[yourUserID].assingment4_1.tar.[Z,gz] and [yourUserID].assingment4_2.txt
• When you have finished, submit the files using the
departmental dropbox.
Here are the contents of CSCE215 directory that contains the program and files associated with it:
main.cpp
#include <iostream>
#include <string>
using namespace std;
#include "name.h"
int main () {
name myName;
myName.SetLast(LAST);
myName.SetMiddle(MI);
myName.SetFirst(FIRST);
cout <<"My name
is: ";
myName.PrintFirst();
myName.PrintMiddle();
myName.PrintLast();
return 0;
}
Makefile
# makefile to build a program
# program depends on components: name and main
myname: main.o name.o
g++ -g main.o name.o -o myname
# name.cpp has it's own header file
name.o: name.cpp
name.h
g++ -c -g name.cpp
# main.cpp also uses the header file name.h
main.o:
main.cpp name.h
g++ -c -g main.cpp
clean:
/bin/rm -f myname *.o
name.cpp
#include <iostream>
#include <string>
using namespace std;
#include "name.h"
void name::GetFirst(string str) {
str=first;
}
void name::SetFirst(string str) {
first=str;
}
void name::GetMiddle(string str) {
str=middle;
}
void name::SetMiddle(string str) {
middle=str;
}
void name::GetLast(string str) {
str=last;
}
void name::SetLast(string str) {
last=str;
}
void name::PrintLast() {
cout << last << "\n";
}
void name::PrintMiddle() {
cout <<
middle;
}
void name::PrintFirst() {
cout <<
first;
}
name.h
#define LAST "tankengine"
#define MI "the "
#define FIRST "thomas "
class name {
private:
string first;
string middle;
string last;
public:
void SetFirst(string str);
void GetFirst(string str);
void SetMiddle(string str);
void GetMiddle(string str);
void SetLast(string str);
void GetLast(string str);
void PrintLast();
void PrintMiddle();
void PrintFirst();
};
readme
/*
Copyright: 2005, All rights reserved.
Program: myname
Version: 1.1
Created: 9/6/05
Revised: 1/22/09
Files: name.cpp, name.h, main.cpp, Makefile
Programmer: Patrick O'Keefe who gratefully acknowledges Dr. Jason
Bakos's kind assistance.
Course: CSCE-215
Assignment: Class Project
Compiler: GNU Gcc version 4.2.3
Target: Linux
Description:
This program attempts string assigment. and other stuff....
Revisions:
There have been no major revisions of this program.
Constants and Variables:
See code for constant and variable descriptions.
or
you could put that kind of info here. Like:
FIRST -> your first name
MIDDLE -> ditto
LAST -> and ditto.
ok here is a change.
ALL OF THOSE FILES ARE LOCATED IN A DIRECTORY /CSCE215
//main.cpp
#include <iostream>
#include <string>
using namespace std;
#include "name.h"
int main () {
name myName;
myName.SetLast(LAST);
myName.SetMiddle(MI);
myName.SetFirst(FIRST);
cout <<"My name is: ";
myName.PrintFirst();
myName.PrintMiddle();
myName.PrintLast();
return 0;
}
====================================================================
//name.cpp
#include <iostream>
#include <string>
using namespace std;
#include "name.h"
void name::GetFirst(string str) {
str=first;
}
void name::SetFirst(string str) {
first=str;
}
void name::GetMiddle(string str) {
str=middle;
}
void name::SetMiddle(string str) {
middle=str;
}
void name::GetLast(string str) {
str=last;
}
void name::SetLast(string str) {
last=str;
}
void name::PrintLast() {
cout << last << "\n";
}
void name::PrintMiddle() {
cout << middle;
}
void name::PrintFirst() {
cout << first;
}
===================================================================
//name.h
#define LAST "grabasandwhich"
#define MI "G."
#define FIRST "bobby "
class name {
private:
string first;
string middle;
string last;
public:
void SetFirst(string str);
void GetFirst(string str);
void SetMiddle(string str);
void GetMiddle(string str);
void SetLast(string str);
void GetLast(string str);
void PrintLast();
void PrintMiddle();
void PrintFirst();
};
===================================================================
sample output:
