Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

Introduction to Programming Assignment: General Looping Exercises

Introduction

Your first assignment will consist of two small C programs that mostly involve basic iteration logic.

Please note that your programs should comply with the commenting and formatting rules as described in class and in the formatting file on eLearning. For example, there should be a header for the whole program that gives the author's name, class name, date, and description. End braces should be commented, and there are alignment and indenting requirements as discussed. A file on eLearning describes these requirements. Please ask if you have any questions.

Program #1: Creation of an ASCII Table

Write a C program that implements that ASCII table given on Slide 30 of the first slide set. That ASCII table will be reproduced below for reference.

Your program should first print out the column headings. It should then print out the binary, octal, decimal, hexadecimal and character versions of the ASCII characters from 32 to 126 (decimal), as indicated in the table. Two vertical columns should be sufficient.

Bin    Oct    Dec   Hex    Char        Bin    Oct   Dec   Hex    Char
                 32
                 33

Note that the columns should run top to bottom (instead of left to right). The range between 32 and 126 has an odd number of entries. Therefore, the left hand column will have one more entry in it than the right hand column.

As we will see shortly, the decimal, octal, and hexadecimal versions of these numbers can be easily displayed using the built-in conversion codes of printf(). The binary versions, however, are more difficult. Two algorithms for converting a decimal number to binary are (1) repeatedly divide the decimal number and its quotients by 2 and collect the remainders (the last remainder collected will be the most significant digit of the result), (2) create the hexadecimal equivalent of the original decimal number and use that hexadecimal intermediate to create the binary. The latter technique depends on the fact that the 16 hexadecimal digits (ranging from 0 to F) exactly correspond to the 16 numbers that can be created out of four bits (ranging from 0000 to 1111). The four bit binary patterns can be created from the hexadecimal digits and concatenated to produce the final result.

For this assignment, let's use the first algorithm: repeated divisions by 2. For an example, let's say our current decimal number is 74 (corresponding to a ‘J' in the ASCII table). If we use this method, we would have:

74 / 2 = 37 R 0
37 / 2 = 18 R 1
18 / 2 = 9 R 0
9 / 2 = 4 R 1
4 / 2 = 2 R 0
2 / 2 = 1 R 0
1 / 2 = 0 R 1

After each division we capture the remainder and then divide the quotient from the previous division by 2. The process stops when the quotient becomes 0 (which it always will). The remainders are then displayed in reverse order (i.e., the last remainder collected is the most significant digit of the result) to produce the final answer: 1001010. Note that these digits should be printed out as they are in the chart, with a space between the first and second nibbles. Furthermore, for the purposes of this assignment, let's also display the leading 0 bit (even though it is not shown in the table). The final result would then be displayed as:

0100 1010

The calculation of the binary should be placed in its own function, which ever method you use. Note that you should never return a pointer from a function to something that was declared locally within that function. Therefore, if you intend to return any kind of an array from a function, it must be passed into the function as an argument. (Alternatively, you could dynamically allocate the array. But we will discuss that issue later in the course.)

Program #2: Drawing Triangles

Write a program that asks the user to enter an integer between 1 and 15. If the number entered is outside that range, your program should print out an error message and re-prompt for another number. (This is an input validation loop.)

Once the user enters a number in the correct range, your program will print out four patterns of asterisks that look like the following. Note that the number provided by the user is equal to the height of the pattern.

Let's say the input value was 8. Then the output should be:

********
*******
******
*****
****
***
**
*

********
*******
******
*****
****
***
**
*
           *
          ***
        *****
      *******
     *********
    ***********
  *************
***************

238_Triangle.jpg

For the final pattern, ask the user for an odd number between 1 and 15. (Your program should use an input validation loop to restrict valid input from the user to odd numbers between 1 and 15.) If that number is 7, then the diagram appears as follows:

1172_Pattern.jpg

Note that, in contrast to the previous diagrams, there are spaces between adjacent asterisks on the first and last lines.

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M92668859
  • Price:- $80

Priced at Now at $80, Verified Solution

Have any Question?


Related Questions in C/C++

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

  • 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