Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

All of this should be able to be done in a linux terminal. Overview: In this ass

ID: 3815105 • Letter: A

Question

All of this should be able to be done in a linux terminal.

Overview: 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. (provided below)

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” (make of comment of where you change this so I can change it to my name please)

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

Source files:

makefile.cpp

# 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

main.cpp

#include
#include
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
#include
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 << " ";
}
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();


};

#include
#include
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;

}

Explanation / Answer

//name.h , I chenged this file

#include<string>
#include<iostream>
/* Added by chegg EA change below define to ur last name ,middle and first name*/
#define LAST "grabasandwhich"
#define MI "G."
#define FIRST "bobby "
/* Added by chegg EA to display your name , Change only above 3 statements*/
using namespace std;

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();


};

----------------------------------------------------

//name.cpp,unchanged

#include"name.h"
#include<iostream>
using namespace std;

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 << " ";
}
void name::PrintMiddle() {
cout << middle;
}
void name::PrintFirst() {
cout << first;
}

--------------------------------------

//main.cpp -unchanged

#include<iostream>
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

myname: main.o name.o
   g++ -g main.o name.o -o myname
name.o: name.cpp name.h
   g++ -c -g name.cpp
main.o: main.cpp name.h
   g++ -c -g main.cpp
clean:
   rm *.o myname
backup:
   mkdir backup
   cp name.h name.cpp main.cpp Makefile backup

---------------------------------------------------------------

to take back p ,type command as below

make backup

which creates the backup directory and copies name.h name.cpp main.cpp and Makefile into backup folder.

I am using online linux terminal , so I am not allowed to run gdb there , I just give you steps to use gdb

1) on command line type gdb myname

$gdb myname

then u will get command propmt like this

(gdb) b main                                                                                                                                                                    

Breakpoint 1 at 0x400b29: file main.cpp, line 7.                                                                                                                                

(gdb) run

once in gdb type b main means u r putting break point at main

you can even give line number with break or b

(gdb) b 10

this puts break point at 10 , then u have to run the program

(gbd) run

this run the program till you have put break point once u are at break point , u can type step