Write a C program that implements that ASCII table

Assignment Help C/C++ Programming
Reference no: EM131840499

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.

Reference no: EM131840499

Questions Cloud

International labour relations : The International Labour Organisation seeks to improve working conditions and eradicate exploitative employment practices through which practices?
Which of the theories of aging presented to you so far : Which of the theories of aging presented to you so far do you feel makes the most compelling argument? Why?
Describe a source of debt financing : Describe a source of debt financing, and discuss when this type of financing would be appropriate for a small business.
Identify four types of strategic change : Balogun and Hailey identify four types of strategic change. What are they and what is their message regarding these changes?
Write a C program that implements that 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.
Deliberate strategy and emergent strategy : What is the difference between deliberate strategy and emergent strategy? Give examples.
Discuss everything about the surroundings : LACE- Explain where you went, the name of the coffee shop, the date and time of day and why you selected this particular place.
Determination of sample size as compared to a confidence : Your superior would like a confidence level of 99%. How does this affect your determination of sample size as compared to a confidence level of 95%
Explain the two opposing forces they face : When a firm enters the international markets, explain the two opposing forces they face.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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