Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make a Bash script with following requirements frontpart #include #ifdef _X3 void pexam1(); void pexam2(); void pexam3(); #endif int main() { #ifdef _X1 printf(In Canada,

Make a Bash script with following requirements

frontpart

#include  #ifdef _X3 void pexam1(); void pexam2(); void pexam3(); #endif int main() { #ifdef _X1 printf("In Canada, there are officially four seasons "); return 0; #endif #ifdef _X2 printf("In Canada, there are four seasons: winter and summer ");

endpart

return 0; #endif #ifdef _X3 pexam1(); pexam2(); pexam3(); return 0; #endif printf("In Canada, there are two seasons: winter and road repair "); return 0; }

pexam1.cpp

#include  void pexam1() { printf("Winter is nice "); }

comp1

#!/bin/bash g++ -o $1 pexam.cpp -D_X1

Task 1. make file named makefile1

The name of your make file must be makefile1 and below is a description of what it should do when used.
Before you start working on the make file makefile1:

Decide what will be your working directory.

Download a text file frontpart and save it on your workstation, then transfer it to moore to the working directory and convert it to a unix text file (using dos2unix). This file is necessary for the make file to work.

Download a text file endpart and save it on your workstation, then transfer it to moore to the working directory and convert it to a unix text file. This file is necessary for the make file to work.

Download a C++ program pexam1.cpp and save it on your workstation, then transfer it to moore and convert it to a unix text file. This program is necessary for the make file to work.

Download a bash script comp1 and save it on your workstation, then transfer it to moore to the working directory and convert it to a unix text file. Then make it executable (using chmod). This script is necessary for the make file to work.

The make file is to be located in the working directory.

It creates a bash script named comp2 from comp1 by replacing every occurrence of a string X1 in the script comp1by a string X2. Then it makes comp2 executable using chmod command.

It creates a C++ program (file) named pexam.cpp by concatenation of the contents of the two files frontpart andendpart (in this order).

It creates a C++ program (file) named pexam2.cpp from pexam1.cpp by substituting every occurrence of a stringwinter in pexam1.cpp by a string summer and by replacing every occurrence of the character 1 by the character2 .

It creates a C++ program (file) named pexam3.cpp from pexam1.cpp by substituting every occurrence of the string winter in pexam1.cpp by the string spring producing a temporary file, and by replacing every occurrence of the character 1 in the temporary file by the character 3 producing pexam1.cpp .

It creates object files pexam1.o, pexam2.o, and pexam3.o by a typical compilation using g++ -c , for instanceg++ -c pexam1.cpp to create pexam1.o .

It creates an executable run1 from pexam.cpp by executing the script comp1 .

It creates an executable run2 from pexam.cpp by executing the script comp2 .

It creates an executable run3 by a compilation of pexam.cpp and linking of pexam1.o, pexam2.o, andpexam3.o together by the g++ compiler with -D_X3 flag, i.e. g++ -o run3 pexam.cpp -D_X3 pexam1.o pexam2.o pexam3.o

It creates an executable run4 from pexam.cpp by a simple compilation of pexam.cpp, i.e. g++ -o run4 pexam.cpp

When typing make -f makefile1 all , the executables run1, run2, run3, and run4 must be created, but no other files can be created Of course, you can use all kind of temporary files, but these must be destroyed before the make file is finished

When typing make -f makefile1 clean , all created files must be removed and the working directory must only contain frontpart, endpart, pexam1.cpp and comp1 as at the beginning.

When you execute run1 , you should see a messageIn Canada, there are officially four seasons

When you execute run2 , you should see a messageIn Canada, there are four seasons: winter and summer

When you execute run3 , you should see messages Winter is nice Summer is nice Spring is nice

When you execute run4, you should see a messageIn Canada, there are two seasons: winter and road repair

A few useful hints:

If you do not have the current directory in the path, you have to refer to the files in your directory in the make file with the prefix ./ , for instance cat ./xxx instead of cat xxx . To quickly add the current directory to the path, execute the commands echo "PATH=$PATH:." >> ~/.bashrc and then source ~/.bashrc

A substring (of any length, including a substring of length 1, i.e. single letter) can be "translated" to any other string by sed command, for instance sed 's/HELLO/HELLO BYE/' fin > fout will read the input file fin and write into the output file fout while replacing the first occurrence of HELLO in each line with HELLO BYE . The filefin will remain unchanged, the changes will be in the file fout .

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

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago