Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Programming Language Expert

Programming Principles and Practice Labs

Lab - Stack Frames and Bash Shell Scripting

Questions -

Q1. Build an executable factorial program from factorial.c, making sure that debugging information is included by the compiler. Run gdb on factorial. Set appropriate breakpoints, and then run factorial within gdb. Continue executing factorial until execution gets to the point pictured by factorial_stack.pdf. At that point, perform a backtrace command to show all the stack frames.

Then without advancing factorial, use appropriate gdb commands to output the values of variables f and i of function main() of factorial. You are NOT permitted to use "backtrace full" for this portion because that would be too easy!

Once you have outputted the desired values, you can exit from gdb.

Q2. Perform steps (a), (b), (c), (d) in succession using bash, and then answer questions (e) and (f). There is one mark for the combination of steps (a), (b), (c), (d).

(a) Execute the command "/bin/ls -l 'which sh' 'which bash'".

(b) Execute the command "set -x". Recall this turns on execution tracing.

(c) For a second time, execute the command "/bin/ls -l 'which sh' 'which bash'".

(d) Execute the command "set -".

(e) Based on the output in step 2a, explain the relationship between sh and bash on tuxworld. Write your answer in lab11.txt.

(f) Explain the operation of the command in part 2c. For example, what commands are being executed, and in what order? Your answer should focus on the output generated because of the -x option being turned on. Write your answer in lab11.txt

Lab - awk and Program Linking

Questions -

Q1. A file called country_data.txt is provided as supplementary data for this question. It consists of four columns: country name, population (in thousands), annual births (in thousands), and literacy rate (%). Before you start the tasks below, familiarize yourself with the contents of the file by examining its content with a program like more (1) or less (1). You do not need to show a log of this in lab12.txt.

(a) Like some data files you may encounter, country_data.txt is not formatted consistently-while most rows contain columns delimited by tabs, a few have one or more columns delimited by spaces. To verify this, use cut(1) to output only the third column (field), and redirect the output to cutout.txt. When you do this, do not change the default delimiter, which is a tab character. Then use awk(1) to output only the third column (field), redirecting the output to awkout.txt. Again, do not change the default delimiter, which in this case is one or more whitespace characters. Finally, use diff(1) to compare cutout.txt and awkout.txt. Submit a log of these steps. You do not need to submit awkout.txt or cutout.txt.

(b) Write an awk(1) command to "clean up" country_data.txt. In other words, make it consistent that a single tab character, and only that, is used to delimit columns (fields) in the file. You will need to read in the file using awk(1), then re-output all of the fields such that they are delimited only by single tabs. Place the output in a file called country_data_cleaned.txt. Your awk(1) script must be specified on the command line, rather than in a separate file. Then repeat question 1a with country_data_cleaned.txt to verify that the output of cut(1) and awk(1) are now identical when outputting the third column.

Use country_data_cleaned.txt to answer questions 1c, 1d, and 1e. You do not need to submit country_data_cleaned.txt.

(c) Write an awk(1) command that lists all the countries having a literacy rate less than 50%. Your command must output only the countries, not the other information in the table. Countries having an unknown literacy rate (represented by the "-" character) must not be included in your output. Your awk(1) code must be specified on the command line, rather than in a separate script.

Remember to use country_data_cleaned.txt as your input file.

(d) Write an awk(1) command that prints the total population (in thousands) of all of the countries whose names begin with "A" and end with "a". Your awk(1) code must be placed in a script called population.awk, and then invoked using "awk -f" on the command line. Upload population.awk as part of your lab submission.

Note that this question does not ask for the population (total or otherwise) for each country whose name matches the pattern. Rather the awk(1) command is to determine the sum (the total) across all the countries whose names match the pattern.

Remember to use country_data_cleaned.txt as your input file.

Hint: the anchors '^' and '$', if used in a regular expression matching against a field, mean "beginning of the field" and "end of the field", respectively.

(e) Write an awk(1) command that reads country_data_cleaned.txt, and outputs the same information except with an additional column. This fifth column contains the country's birth rate (number of children per woman per year). Assume the population of each country is 50% male and 50% female. You may use the default output format for decimal numbers (7 decimal places). Like the other columns, the additional column must be delimited by a tab character.

Your awk(1) code must be specified on the command line, rather than in a separate file, and the output of the command must be redirected to a file country_data_birthrate.txt. Upload your country_data_birthrate.txt file as part of your lab submission.

Q2. Use a pipeline involving date(1) and awk(1) to print out the current month and year in the following format:

Month: Nov

Year: 2011

Your awk(1) code must be specified on the command line, rather than in a separate script.

Attachment:- Assignment Files.rar

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M92863748

Have any Question?


Related Questions in Programming Language

Task - hand execution of arraysoverviewin this task you

Task - Hand Execution of Arrays Overview In this task you will demonstrate how arrays work by hand executing a number of small code snippets. Instructions Watch the Hand Execution with Arrays video, this shows how to ste ...

Assignment task -q1 a the fibonacci numbers are the numbers

Assignment Task - Q1. (a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the ...

Assignment - haskell program for regular expression

Assignment - Haskell Program for Regular Expression Matching Your assignment is to modify the slowgrep.hs Haskell program presented in class and the online notes, according to the instructions below. You may carry out th ...

Task working with arraysoverviewin this task you will

Task: Working with Arrays Overview In this task you will create a simple program which will create and work with an array of strings. This array will then be populated with values, printed out to the console, and then, w ...

Task arrays and structsoverviewin this task you will

Task: Arrays and Structs Overview In this task you will continue to work on the knight database to help Camelot keep track of all of their knights. We can now add a kingdom struct to help work with and manage all of the ...

Assignment - horse race meetingthe assignment will assess

Assignment - Horse Race Meeting The Assignment will assess competencies for ICTPRG524 Develop high level object-oriented class specifications. Summary The assignment is to design the classes that are necessary for the ad ...

Php amp session managment assignment -this assignment looks

PHP & SESSION MANAGMENT ASSIGNMENT - This assignment looks at using PHP for creating cookies and session management. Class Exercise - Web Project: Member Registration/Login This exercise will cover adding data connectivi ...

Background informationthis assignment tests your

Background Information This assignment tests your understanding of and ability to apply the programming concepts we have covered throughout the unit. The concepts covered in the second half of the unit build upon the fun ...

Structs and enumsoverviewin this task you will create a

Structs and Enums Overview In this task you will create a knight database to help Camelot keep track of all of their knights. Instructions Lets get started. 1. What the topic 5 videos, these will guide you through buildi ...

Overviewthis tasks provides you an opportunity to get

Overview This tasks provides you an opportunity to get feedback on your Learning Summary Report. The Learning Summary Report outlines how the work you have completed demonstrates that you have met all of the unit's learn ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As