Question: Basic C++ programming Part A) Simple Diamond 20 marks Create the C program q1a_simple_diamond.c to produce a program which takes 1 argument, the height H

Basic C++ programming

Part A) Simple Diamond 20 marks Create the C program q1a_simple_diamond.c to produce a program which takes 1 argument, the height H of the diamond. Prints a diamond which is made up of H rows of asterisk (a.k.a. star, *) characters and spaces following this specification:

The diamonds top and bottom rows must both be a single asterisk (same line if H=1)

Subsequent rows must grow or shrink by 2 asterisks, according to the overall shape

A single row in the middle of the diamond must have exactly H asterisks (no spaces in this one)

The first asterisk in the middle row must appear at the very beginning of the line

The asterisks in all rows must be perfectly centered with respect to the middle row Your program is never allowed to segmentation fault, no matter how it is run. To prevent this, input checking must be performed:

The program needs exactly one argument after the program name, no more and no less.

Otherwise print: ERROR: Wrong number of arguments. One required.

The height argument must be a positive integer and odd (ensures the overall shape works). Otherwise print: ERROR: Bad argument. Height must be positive odd integer.

Part B) Sierpiski Diamond 40 marks A fractal refers to a recursively defined shape, such that infinite variations are possible at increasingly smaller scales. One such is known as the Sierpiski Triangle, and we will make our next diamond from two of these vertically mirrored. More information at: Wikipedia. Create a second C program, q1b_sierpinski_diamond.c, which prints a modified diamond, such that each of the top and bottom half are Sierpiski Triangles. Your program should take two arguments: the height of the diamond, H, and the fractal level, L. Again, the diamond has a precise format: The level L=1 diamond must be identical to the simple diamond with the given height, H. For each level beyond 1, you must sub-divide top and bottom triangles using Sierpiskis rule. Replace a H/2 triangle whose tip touches the bottom of the original with spaces. This leaves 3 triangles, each with height H/2 and level L-1, one above the missing triangle, and two beside it. We must continue recursively sub-dividing each remaining triangle until we reach level L=1. Your program is never allowed to segmentation fault, no matter how it is run. To prevent this, input checking must be performed: Height H must meet all the same conditions as above, with the same error messages. Height H must allow us to perfectly divide the triangle each time. This means that tri_height=ceil(H/2) must be a power of 2, with tri_height >= 2 L-1 . Otherwise print ERROR: Height does not allow evenly dividing requested number of levels.

Question 2 Wiki Browsing 40 marks Wikipedia is a community developed encyclopedia that contains loads of useful information, if you know how to navigate it properly. You must create a C program, called q2_extract_wiki_links.c, that parses pages from the site Wikipedia using Cs text processing functions found in . Print the names of all links to other Wikipedia pages that you find to the terminal. Those links appear in this form: easy to read description You must match the bold text, but elements in italics can be anything. Please note that PageName is just an example. The real name will be something meaningful like Chicken. All of the following are valid: Chicken Chickens poultry However, the following should not be matched (because something in the bold part is incorrect): Chicken (this is a link to a normal website off Wikipedia) Chicken (missing the title= section)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!