This is a home work assignment for C++ in unix Have to use a bash script Documen
ID: 3782906 • Letter: T
Question
This is a home work assignment for C++ in unix
Have to use a bash script
Document all the shell work done to complete the assignment using the “screen –L” program or putty logging. This will keep a log of all your shell work. You will need to turn in the output files from “screen –L”/putty. See “Deliverables” below.
With console logging enabled, write a program that consists of two C++ source files. The first file contains the main() routine and the second file contains a C++ procedure.
From within main(), you must display the count of command line arguments to stdout. Further, you must display the value of each command line argument to stdout. Finally, you must call the procedure that is defined in the second file.
From within the procedure defined in the second file, you must display a log message that states you are inside the procedure. This log message must be sent to stderr.
You are then to create a shell script for compiling your code. The script will individually compile each file and generate the intermediate object file. Once the object files are created, the script will call the linker and link the object files into an executable. Your shell script should echo what it is doing at each step to stdout.
You are then to create a second shell script that will run your program several times with varying command line arguments. Each time you call your program, you should append the stdout to an output file called stdout.log and you should append the stderr to an output file called stderr.log. Your shell script should echo what it is doing at each step to stdout.
Example Output
$> compile.sh
Setting TEMPDIR environment variable to /scratch Compiling file1.cc
Compiling file12.cc
Linking files to create executable hw1
Done
$> run.sh
Running 'hw1' with 0 arguments:
stdout appended to stdout.txt
stderr appended to stderr.txt
Running 'hw1' with 1 argument:
stdout appended to stdout.txt
stderr appended to stderr.txt
Running 'hw1' with 5 arguments:
stdout appended to stdout.txt
stderr appended to stderr.txt
$> more stdout.txt
argc was: 1
./hw1
Done!
argc was: 2
./hw1
abc
Done!
argc was: 6
./hw1
a
b
c
d
e
Done!
$> more stderr.txt
Inside proc1() as stderr
Inside proc1() as stderr
Inside proc1() as stderr
Explanation / Answer
To insert space characters whenever the tab key is pressed, set the 'expandtab' option: set expandtab With this option set, if you want to enter a real tab character use Ctrl-V key sequence. To control the number of space characters that will be inserted when the tab key is pressed, set the 'tabstop' option. For example, to insert 4 spaces for a tab, use: set tabstop=4 After the 'expandtab' option is set, all the new tab characters entered will be changed to spaces. This will not affect the existing tab characters. To change all the existing tab characters to match the current tab settings, use :retab To change the number of space characters inserted for indentation, use the 'shiftwidth' option: set shiftwidth=4 For example, to get the following coding style, - No tabs in the source file - All tab characters are 4 space characters use the following set of options: set tabstop=4 set shiftwidth=4 set expandtabRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.