Build an executable factorial program

Assignment Help Programming Languages
Reference no: EM132027096

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

Reference no: EM132027096

Questions Cloud

Describe the organizations focus and what they are doing : Provide a quick introduction to the organization you have chosen. Describe the organization's focus and what they are doing to promote positive change.
Summarize three ways to keep your students engaged : "Student Engagement Strategies" - Summarize three ways to keep your students engaged. Include drawings of classroom arrangements and how you would implement.
What potential liabilities could exist : What potential liabilities could exist by having students of the XYZ University participate with service learning and the organization?
Which data set is more variable with relation to the mean : Which student scored better with relation to the other students in the distribution? Which data set is more variable with relation to the mean?
Build an executable factorial program : CMPT 214: Programming Principles and Practice Labs. Lab - Stack Frames and Bash Shell Scripting. Build an executable factorial program from factorial.c
Calculate confidence intervals is a standard normal : In a study using 10 samples, and in which the population variance is known, the distribution that should be used to calculate confidence intervals
Teenagers in the population feel : Use a 0.05 significance level to test the claim that fewer than half of all teenagers in the population feel that grades are their greatest source of pressure.
Confidence interval for the population mean : Construct a 90?% confidence interval for the population mean µ. Also what is the margin of error of µ?? Interpret the results.
What are the consequences for the organization : Historical background of the issue/topic (1page). What are the consequences for the organization if this issue is not addressed appropriately? (1 page)

Reviews

len2027096

6/22/2018 3:53:34 AM

I need the Q1Q2 from lab11 and Q1Q2 from lab12. Please give me these file: lab11.txt, lab12.txt, population.awk, country_data_birthrate.txt and nsid: sil600 if need it. Lab - Stack Frames and Bash Shell Scripting. Lab Demo - At the beginning of this lab, the lab instructor will give a brief presentation about symbolic links in the UNIX file system. This information will be helpful in answering question 2e. You can also read about symbolic links in pages 109 to 118 of the Sobell textbook. Lab Details - This lab is out of a total of 20 marks; the number of marks allocated to each question is indicated below. When you have completed the exercises below, you should prepare a plain text log file named lab11.txt as described in the Submission Instructions posted on the course Moodle. For this lab, submit the following files: lab11.txt and move_columns.sh.

len2027096

6/22/2018 3:53:27 AM

In addition to the regular console log, include your solution to questions 2(d), 2(e), 3(e) and 6(f) at the bottom of lab11.txt. Be sure to add identifying information to clearly distinguish each question. Remember to put your name, student number and NSID at the beginning of any files you are submitting. Special Directions - Unless otherwise specified, all commands should be run on tuxworld using the bash shell. For this lab, you will need various supplementary files. They are in the file Lab11Files.tar associated with this lab. Download Lab11Files.tar and unpack it prior to beginning the questions or tasks below. You do not need to show a log of the download or unpacking.

len2027096

6/22/2018 3:53:18 AM

Lab - awk and Program Linking - Lab Details - This lab is out of a total of 18 marks; the number of marks allocated to each question is indicated below. When you have completed the exercises below, you should prepare a plain text log file named lab12.txt as described in the Submission Instructions posted on the course Moodle. For this lab, submit the following files: lab12.txt, population.awk and country_data_birthrate.txt. Remember to put your name, student number and NSID at the beginning of any files you are submitting. Special Directions - Unless otherwise specified, all commands should be run on tuxworld using the bash shell.

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd