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

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 ...

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 ...

Question - create a microsoft word macro using vba visual

Question - Create a Microsoft Word macro using VBA (Visual Basic for Applications). Name the macro "highlight." The macro should highlight every third line of text in a document. (Imagine creating highlighting that will ...

Assignmentquestion onegiving the following code snippet

Assignment Question One Giving the following code snippet. What kind of errors you will get and how can you correct it. A. public class HelloJava { public static void main(String args[]) { int x=10; int y=2; System.out.p ...

Assignment - proposal literature review research method1

Assignment - Proposal, Literature Review, Research Method 1. Abstract - Summary of the knowledge gap: problems of the existing research - Aim of the research, summary of what this project is to achieve - Summary of the a ...

1 write a function named check that has three parameters

1. Write a function named check () that has three parameters. The first parameter should accept an integer number, andthe second and third parameters should accept a double-precision number. The function body should just ...

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 ...

Task silly name testeroverviewcontrol flow allows us to

Task: Silly Name Tester Overview Control flow allows us to alter the order in which our programs execute. Building on our knowledge of variables, we can now use control flow to create programs that perform more than just ...

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 ...

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 ...

  • 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