Hall H.

asked • 03/01/21

Help with Computer Science assignment

#1.


Create the Hello World program using vi. Save it in your home directory. Instead of the using the “Hello World!” in cout, replace it with “Hello, your name!”

Compile the program using g++. This should create a binary executable file called a.out. If you have any typos, the compiler will indicate the errors. In many instances, the error will not be in the line indicated, so, double check your code. To run the program, remember that you to type ./a.out


#2


Compiling your source code files can be tedious, especially when you want to include several source files and have to type the compiling command every time you want to do it.

Makefiles are special format files that together with the make utility will help you to automatically build and manage your projects.

First type this program using vi

#include <iostream>

#include <cstring>

 

void reverse_string(char s[]) {

  int i,j,c;

  for(i = 0, j = strlen(s)-1; i < j ; i++, j-- ) {

         c = s[i];

         s[i] = s[j];

         s[j] = c;

  }

}

 

int main() {

  char s[] ="reverse me";

  reverse_string(s);

  std::cout << s << std::endl;

  return 0;

}

Where you see “reverse me”, replace it with your full name.

Now, instead of using g++ to compile it, you will create a makefile, using vi, to compile the program.

The specification that make uses is generally saved in a file named makefile. Here is a makefile to build the traditional “Hello, World” program:

 

The format in which this must be typed is:

 

target: program files

(press TAB) g++ source_files

 

To build the program execute by typing:

 

$make

 

at the command prompt of your favorite shell. This will cause the make program to read the makefile and build the first target it finds there:

 

$ make

g++ hello.c -o hello      << this will be displayed when you run make or something similar

 

If a target is included as a command-line argument, that target is updated. If no command-line targets are given, then the first target in the file is used, called the default goal. Typically the default goal in most makefiles is to build a program. This usually involves many steps.

 

Now, create a makefile to compile your reverseit program. If you have typed the makefile properly, once youl type make at the shell prompt and that will compile your program. Test the program after you run make by typing ./reverseit. If nothing happens, most likely you have typos on your program and/or the makefile.



1 Expert Answer

By:

Patrick B. answered • 03/02/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.