Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C please. Your assignment: write a C-program, convert that reads decimal integers (you can assume non- negative values) from standard-in (a.k.a., the keyboard) and

image text in transcribed

image text in transcribed

In C please.

Your assignment: write a C-program, convert that reads decimal integers (you can assume non- negative values) from standard-in (a.k.a., the keyboard) and prints the representation of each value in either hex or binary. The program will continue to read values until reaching the end- of-file signal. What is the end-of-file for the keyboard? Control-D. We use control characters so often, control is usually written with a carrot. For example, "D. Which representation should the program print? Convert takes a single command-line argument that is either "-" or "-6". Of course "x" indicates that the program should print the value in hexadecimal; "-b" indicates that it should print binary. OUTCOMES: Comfortable with C programming, the C library, and the C tool chain. Properly use some of the C bit-wise operators . Produce well formatted code. Total Points: 15 Correctness (10) o Correctly print binary value o Correctly print hexadecimal value o Correctly print values without using printf's %x format character o Must use bitwise operators Quality (5) o Programming style (organization, indenting, comments, symbol names, etc.) o Organization (Intro to file, meaningful grouping, etc) TEST CASES: $./convert - 1234 Ox4d2 4321 Ox10e1 AD $./convert-b 1234 100 1101 0010 4321 1 0000 1110 0001 AD $./convert Usage:./convert [-xl-b] The dollar sign, $, is a generic shell prompt. Your prompt will probably be different. Carrot-D (^D) is shorthand for control-D. We will see why later, control-D on a line by itself signals end- of-file to the program. CODING STYLE: 1) Use meaningful names that give the reader a clue as to the purpose of the thing being named. 2) Avoid the repeated use of numeric constants. For any numeric constants used in your program, define a static constant: static const float Pl= 3.141592653589793; From then on, use the symbol in place of the value. There is a convention to use ALL CAPS for constants. 3) Use comments at the start of the program to identify the purpose of the program. /* This program converts decimal to either binary * or hexadecimal... *7 4) Use comments at the start of each function to describe the purpose of the function, the purpose of each parameter to the function, and the return value from the function. /* Read Decimal This function reads and returns a single, decimal integer from stdin. * NOTE: Most of the parsing work is performed by scanf. *1 int read_decimal() 5) Avoid in-line comments in the code itself. 6) Use comments at the start of each section of the program to explain what that part of the program does. 7) Use consistent indentation. These are general guidelines to help you produce superior code. However, as a software professional, it is your job to know when to deviate from these rules to produce code that is as easy to read and understand as possible

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions