These are the instructions for my assignment. Ignore the parts referring to where to place the assignment in subdirectories and what not. Just focus on the parts in bold. I don't want the assignment done by anyone or anything like that, but like an outline of some sort to help me understand what I am suppose to do.
Place all programs for this assignment in a subdirectory off your home directory on et791. Name this subdirectory assignment_7.
Write a program with functions. First, prompt user for input of three float numbers. Then Use three different functions to calculate maximum(function1), minimum(function2) and median(function3) of these three numbers. Print the returned result in the main() function. Call this program assignment_7a.c.
Modify the assignment_7a.c, take the printing code from the previous program and make another function called display. Call this function to display the maximum, minimum and median. Call this program assignment_7b.c.
Don't understand this with the functionsHomework assignment, don't understand the concept
Page 1 of 1
5 Replies - 557 Views - Last Post: 31 October 2008 - 02:48 AM
Replies To: Don't understand this with the functions
#2
Re: Don't understand this with the functions
Posted 30 October 2008 - 10:07 AM
you have to declare three floats
which you can input and output with these functions
whats your problem exactly? did you understand how functions are working? when yes, this assignment would not be a problem for an beginner too.
float number1, number2, number3;
which you can input and output with these functions
void input(); float maximum(); float minimum(); float median(); float display();
whats your problem exactly? did you understand how functions are working? when yes, this assignment would not be a problem for an beginner too.
#3
Re: Don't understand this with the functions
Posted 30 October 2008 - 10:07 AM
bbarker3, on 30 Oct, 2008 - 11:37 AM, said:
Write a program with functions. First, prompt user for input of three float numbers. Then Use three different functions to calculate maximum(function1), minimum(function2) and median(function3) of these three numbers. Print the returned result in the main() function.
/* Headers */
/* Min function */
/* Max function */
/* Median function */
/* Main */
int main(void)
{
/* Get Input */
/* Process Input */
/* Display Results */
return 0;
}
bbarker3, on 30 Oct, 2008 - 11:37 AM, said:
Modify the assignment_7a.c, take the printing code from the previous program and make another function called display. Call this function to display the maximum, minimum and median. Call this program assignment_7b.c.
For the second part, take the code to display the results out of main{} and into its own function.
#4
Re: Don't understand this with the functions
Posted 30 October 2008 - 12:55 PM
bbarker3, on 30 Oct, 2008 - 09:37 AM, said:
These are the instructions for my assignment. Ignore the parts referring to where to place the assignment in subdirectories and what not. Just focus on the parts in bold. I don't want the assignment done by anyone or anything like that, but like an outline of some sort to help me understand what I am suppose to do.
Place all programs for this assignment in a subdirectory off your home directory on et791. Name this subdirectory assignment_7.
Write a program with functions. First, prompt user for input of three float numbers. Then Use three different functions to calculate maximum(function1), minimum(function2) and median(function3) of these three numbers. Print the returned result in the main() function. Call this program assignment_7a.c.
Modify the assignment_7a.c, take the printing code from the previous program and make another function called display. Call this function to display the maximum, minimum and median. Call this program assignment_7b.c.
Place all programs for this assignment in a subdirectory off your home directory on et791. Name this subdirectory assignment_7.
Write a program with functions. First, prompt user for input of three float numbers. Then Use three different functions to calculate maximum(function1), minimum(function2) and median(function3) of these three numbers. Print the returned result in the main() function. Call this program assignment_7a.c.
Modify the assignment_7a.c, take the printing code from the previous program and make another function called display. Call this function to display the maximum, minimum and median. Call this program assignment_7b.c.
What college/university are you attending? Curious.
#5
Re: Don't understand this with the functions
Posted 30 October 2008 - 05:36 PM
Hyper, on 30 Oct, 2008 - 12:55 PM, said:
bbarker3, on 30 Oct, 2008 - 09:37 AM, said:
These are the instructions for my assignment. Ignore the parts referring to where to place the assignment in subdirectories and what not. Just focus on the parts in bold. I don't want the assignment done by anyone or anything like that, but like an outline of some sort to help me understand what I am suppose to do.
Place all programs for this assignment in a subdirectory off your home directory on et791. Name this subdirectory assignment_7.
Write a program with functions. First, prompt user for input of three float numbers. Then Use three different functions to calculate maximum(function1), minimum(function2) and median(function3) of these three numbers. Print the returned result in the main() function. Call this program assignment_7a.c.
Modify the assignment_7a.c, take the printing code from the previous program and make another function called display. Call this function to display the maximum, minimum and median. Call this program assignment_7b.c.
Place all programs for this assignment in a subdirectory off your home directory on et791. Name this subdirectory assignment_7.
Write a program with functions. First, prompt user for input of three float numbers. Then Use three different functions to calculate maximum(function1), minimum(function2) and median(function3) of these three numbers. Print the returned result in the main() function. Call this program assignment_7a.c.
Modify the assignment_7a.c, take the printing code from the previous program and make another function called display. Call this function to display the maximum, minimum and median. Call this program assignment_7b.c.
What college/university are you attending? Curious.
University of Toledo in Ohio
#6
Re: Don't understand this with the functions
Posted 31 October 2008 - 02:48 AM
Here's a C version that takes a little different approach ...
#include <stdio.h>
/*
A program in C which takes three input integers from the user
and displays the minimum, middle and maximum integers
given by the user as input.
Uses a simple bubble sort for ordering the numbers.
Note: C doesn't support passing by ref so easily as C++ does ...
One must pass the address in ... of the object being passed
then 'catch' that address as a 'pointer' (i.e. an address) for the object
*/
/* Here ... we tell the compiler these are all pointers to int */
void sort(int* a, int* b, int* c)
{
int temp;
/*
using a BUBBLE SORT: first ... 'bubble' the highest to c
then 'bubble' the next highest to b ... and we are done
NOTE: below ...
*a and *b take the int values at addresses a and b
since on the top line we told the compiler
that a and b were pointers to (i.e. addresses for) 'int'
*/
if( *a > *b ) /* swap */
{
temp = *a;
*a = *b;
*b = temp;
}
if( *b > *c ) /* swap */
{
temp = *b;
*b = *c;
*c = temp;
}
if( *a > *b ) /* swap */
{
temp = *a;
*a = *b;
*b = temp;
}
}
int main()
{
int a=0, b, c, t;
for(;;)/>
{
printf( "Input 3 non zero integers to be ordered : " );
a=b=c=0; /* use these zeros as flags for bad data input */
scanf( "%d%d%d", &a, &b, &c );
while( (t=getchar()) != '\n' ) ; /* flush stdin */
/* check for bad data ... */
if( a==0 || b==0 || c== 0 )
{
printf("\nIntegers only ... ");
continue; /* from the top of the for loop ...*/
}
sort( &a, &b, &c ); /* pass addresses to sort function */
printf( "Now in order %d %d %d\n\n", a, b, c );
printf("Press 'Enter' to continue ... 'x' to exit ... ");
t =getchar();
if ( t=='x' || t=='X' ) return 0;
if ( t !='\n') while( (t=getchar()) != '\n' ) ; /* flush stdin */
}
}
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|