Purchase Solution

Rewriting a C program using functions and top-down design

Not what you're looking for?

Ask Custom Question

Program Functions

Design and code an ANSI Standard C program which enhances the code below only so as to make it a modular program. (each of the program four tasks of ask, get, alter and display are now separate functions).

This will necessitate designing appropriate ask, get, alter and display functions. It will also necessitate coding four ANSI Standard function prototypes, function calls in main() and single-task function definitions. Explain in a brief function comment, what the function's task is and if it needs to have data passed into it, if it needs to return a value to the method that called it (main) or possibly both or neither.

Do not use any global variables, only local variables - in other words, declare all your variables inside and at the top of your functions, to include main().
===============
Code to enhance:

#include <stdio.h>

int main()
{

float fahrenheit;
float celsius;

printf("Enter the Fahrenheit temperature as a whole number: ");
scanf("%f",&fahrenheit);

celsius = 5.0/9.0*(fahrenheit - 32);

printf("Fahrenheit temperature %0.2fn",fahrenheit);
printf("Celsius temperature %0.2fn",celsius);
}

Purchase this Solution

Solution Summary

This solution starts with a C program that converts Fahrenheit to Celsius temperatures using the standard simple approach. It then shows how to rewrite the program using functions for the basic steps in the algorithm. Complete C source code is provided.

Solution Preview

Using functions is a useful and powerful aspect to a C program. To use a function you must first declare the function using a function prototype. Then you must provide an implementation for the function.

The function prototype includes the name of the function, the return type, and a list of any parameters that the function takes. This posting requires four ...

Purchase this Solution


Free BrainMass Quizzes
Javscript Basics

Quiz on basics of javascript programming language.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

C# variables and classes

This quiz contains questions about C# classes and variables.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.