Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please do this for me in Linux. The driver.cpp, and circle.h are shown below. Intro: In Linux and Unix system in order to create programs/applications

Please do this for me in Linux. The driver.cpp, and circle.h are shown below.

Intro:

In Linux and Unix system in order to create programs/applications we need to use the

command line equivalent of a compiler and debugger. On Linux systems there is a compiler

that is open source and provided as a package an administrator can install. These are Known

as GNU Compilers, the packages that are included is for c and c++ as well as some older

programing languages such as Fortran and perl. We will be focusing on gcc(c compiler) and

g++(c++ compiler).

Lab:

Objective: To learn how to compile and debug code on Linux platforms using the command

line tools gdb and g++, There will be 4 syntax errors and 3 logical errors in the code.

Deliverables:

Take a screen shot of the program running before each correction, and after each correction,

so i can see the progress.

Task Compiling:

1) Download the two files from blackboard, driver.cpp, and circle.h

2) Create a new directory to store the files in

3) Compile the code

a) Run the command g++ driver.cpp -o executable_name, this will compile the

code both for driver.cpp and the referenced file circle.h

4) Using the error messages that the compiler gives you correct the syntax errors

5) repeat this process until all syntax errors are resolved.

When compiling code, the compiler checks the files for syntax errors and link errors

first, if it finds any errors it displays them on the screen and aborts compiling the code. Other

Compilers such as Visual Studio and Eclipse do something similar; the major difference is in

how they word the errors. Some errors may look similar and some may not.

To find the syntax errors are straightforward every time you compile the code the

compiler will tell you any syntax errors. Logical errors on the other hand a compiler cannot

help you with, in these cases we use a debugger. A debugger is an application that acts as a

wrapper for the application execution, when you use a debugger the program you are

debugging executes as a child process to the debugger and using various system calls

intercepts and gains control after each line of execution of the child process. The

user/developer has control of the flow of the program. A debugger also gets a snapshot of the

application memory of the program that you are debugging, this way the user can track the

values of each variable after each line executes.

Task Debugging:

Debugging applications in Linux using the debugger known gdb

Reference:http://web.eecs.umich.edu/~sugih/pointers/gdbQS.html

1) Compile the code using g++ driver.cpp o executable_name g, this will Compile

the code and create symbols for the debugger to use.

2) Run gdb on your executable

gdb executable_name

3) When in gdb(when you have a prompt that looks like (gdb)) type the command

start

This will execute the code for the executable that you are working on.

4) Type continue to execute the next line of code in your executable.

If you hit an error the debugger quits the execution of the code,

5) Read the error messages and return to the bash shell by typing quit in gdb.

6) Make the corrections to the code and re-compile the code.

7) Repeat this process until all logical errors is corrected.

circle-1.h

#include #ifndef CIRCLE_H #define CIRCLE_H using namespace std; class Circle { private: double radius;//radius of the circle double * area;//area of the circle double * circumference;//circumferencee of the circle static const double pi=3.1415;// the value of pi public: Circle(){radius=0;area=new double;area=0;circumference= new double;} void set_rad(double rad){radius = rad;}; double compute_area() {*area = (pi*pow(radius,2.0));return *area;}; double compute_circumference() {*(circumference+1)=2*pi*radius;return *circumference;} ~Circle(); }; #endif

circle_1-1.cpp

#include #include "circle.h" using namespace std; int main() {

double users_radius;// value to store users given radius value; Circle * first_circle;// define a pointer to a circle first_circle = new Circle();// allocate memory for the object and call the constructor

cout<<"This Program computes various metrics of a circle">users_radus;

first_circle->set_rad(users_radius);

cout<<"Area of circle is:"<compute_circumference()<

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

Compare and contrast X.25, frame relay, ATM, and Ethernet services.

Answered: 1 week ago