-
So LOST!!!
I know this is a simple program to write, but i seriously am lost...if someone could help me out... :confused:
if not show me the code ,at least to get me started...
of course. if you could send me the finished project it would begreat:D ... since its due monday!! but if not, just some help would be greatly appreciated!! Below is the assignment...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Write a program in C which will keep a list of employees, their first and last name, their employee number, and their salary.
The program should be able to hold up to 30 employees. To enter the data into the program, the user will be asked for each employee to enter first name, middle initial, last name, employee number, and salary.
Enter employee information:
Enter employee number: 123
Enter first name: John
Enter middle initial: A.
Enter last name: Smith
Enter salary: 38471.25
After the employee information has been entered, the program should display the information entered in the following format:
By Employee Number:
Employee Number
First name
M.I.
Last name
Salary
123
John
A.
Smith
43123.25
150
Mary
B.
Jones
48381.31
182
Lester
C.
Harris
32100.10
Enter selection:
(N) List always at sorted by employee number
(F) List sorted by first name
(L) List sorted by last name
(S) List sorted by salary
(Q) Quit
For each selection display the list in the preferred sorted order.
By Salary:
Employee Number
First name
M.I.
Last name
Salary
182
Lester
C.
Harris
32100.10
123
John
A.
Smith
43123.25
150
Mary
B.
Jones
48381.31
By First Name:
Employee Number
Employee Name:
Salary:
123
John A. Smith
43123.25
182
Lester C. Harris
32100.10
150
Mary B. Jones
48381.31
By Last Name:
Employee Number
Employee Name:
Salary:
182
Harrison, Lester C.
32100.10
150
Jones, Mary B.
48381.31
123
Smith, John A.
43123.25
Thank you for your help!!
Drew
-
Something along these lines, but it's been a while since I've used the struct.
Code:
struct employ
{
char name[65];
char initial;
char fname[30];
char lname[30]
long ID;
float salary;
};
main...
struct employ myemp[30];
for(index=0; index < 30; index++)
{
fgets(myemp[index].name, 30, stdin);
... do similar stuff with other records
}
use a loop to print out the struct stuff similar to how you read it in.
HTH
-
What exactly are you stuck with? Post what you have written so far, and say specifically where your problems are.
I know you're only joking about getting someone to complete it for you, but please don't post complete assignments, you won't get a very good response.
-
diff question
Before I ask about the previous posted problem...I have been working on this assignment to calculate the mean, std deviation, variance, smallest and largest number based on numbers the user inputs...below is what i have so far...it is pretty much complete except i cannot get the std dev , median, and var to display...i know it has to do with my printf statements..if someone could take a look and let me know what i am doing wrong it would be greatly appreciated...thank you
Drew
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
double totalarray(double *x, int n);
double smallest_value(double *x, int n);
double largest_value(double *x, int n);
double median(double *x, int n);
double average(double x[], int n);
double stdeviation (double x);
double var(double x);
void main()
{
double *base, *calcarray;
int i,n;
double average,temp,total,smallest,largest,var, stdeviation,
median;
printf("\nEnter the total number of double precision floating
point values to be entered: ");
scanf("%d", &n);
base =(double*) malloc (n*sizeof(double));
if (base == NULL)
{
printf("\n\nMemory Allocation failure!\n\n");
exit(1);
}
for (i=0; i<n; i++)
{
printf("\nEnter number %d: ", i+1);
scanf("%lf", &temp);
base[i] = temp;
}
calcarray =(double*) malloc (n*sizeof(double));
if (calcarray == NULL)
{
printf("\n\nMemory Allocation failure!\n\n");
exit(1);
}
for (i=0; i<n; i++)
{
printf("\nEnter number %d: ", i+1);
scanf("%lf", &temp);
calcarray[i] = temp;
}
total = totalarray(base,n);
printf("\nThe total is %.2lf", total);
smallest = smallest_value(base,n);
printf("\nThe smallest is %.2lf\n\n",smallest);
largest = largest_value(base,n);
printf("\nThe largest is %.2lf\n\n",largest);
average = total/n;
printf("\nThe average is %.2lf\n\n", average);
median =
printf("\nThe median is %.2lf\n\n", median);
var =
printf("\nThe variance is %.2lf\n\n", var);
stdeviation =
printf("\nThe standard deviation is %.2lf\n\n", stdeviation);
free(base);
free(calcarray);
}
/******************
total for array
******************/
double totalarray(double *x, int n)
{
double result = 0.0;
int i;
for (i=0; i<n; i++)
{
result = x[i] + result;
}
return(result);
}
/**********************
find smallest value
**********************/
double smallest_value(double *x, int n)
{
double result;
int i;
result = x[0];
for(i=1; i<n; i++)
{
if(x[i]<result)
result= x[i];
}
return(result);
}
/***********************
find largest value
***********************/
double largest_value(double *x, int n)
{
double result;
int i;
result = x[0];
for(i=1; i<n; i++)
{
if(x[i]>result)
result= x[i];
}
return(result);
}
/**********************
median
**********************/
double median(double *x, int n)
{
double result;
if (n%2)
{
result= x[n/2];
}
else
{
result= ((x[n/2] + x[n/2-1])/2);
}
return (result);
}
/****************
bubble sort
*****************/
void bubble(double x[], int n)
{
int i, sorted;
double temp;
sorted = 0;
while(!sorted)
{
sorted =1;
for(i=0; i<n-1; i++)
{
if(x[i]>x[i+1])
{
temp = x[i];
x[i] = x[i+1];
x[i+1] = temp;
sorted = 0;
}
}
}
}
/*****************
average array
*****************/
double average(double x[], int n)
{
double result = 0.0;
result = totalarray(x, n)/n;
return(result);
}
/**************************/
double stdeviation (double x)
{
double deviation;
deviation = sqrt(x);
return(deviation);
}
double var(double x)
{
double variance, n;
variance = totalarray(x,n)/(n-1);
return(variance);
}
-
easier to read
Code:
/*
#include <stdio.h>
#include <math.h>
#include <malloc.h>
#include <stdlib.h>
double totalarray(double *x, int n);
double smallest_value(double *x, int n);
double largest_value(double *x, int n);
double median(double *x, int n);
double average(double x[], int n);
double stdeviation (double x);
double var(double x);
void main()
{
double *base, *calcarray;
int i,n;
double average,temp,total,smallest,largest,var, stdeviation, median;
printf("\nEnter the total number of double precision floating point values to be entered: ");
scanf("%d", &n);
base =(double*) malloc (n*sizeof(double));
if (base == NULL)
{
printf("\n\nMemory Allocation failure!\n\n");
exit(1);
}
for (i=0; i<n; i++)
{
printf("\nEnter number %d: ", i+1);
scanf("%lf", &temp);
base[i] = temp;
}
calcarray =(double*) malloc (n*sizeof(double));
if (calcarray == NULL)
{
printf("\n\nMemory Allocation failure!\n\n");
exit(1);
}
for (i=0; i<n; i++)
{
printf("\nEnter number %d: ", i+1);
scanf("%lf", &temp);
calcarray[i] = temp;
}
total = totalarray(base,n);
printf("\nThe total is %.2lf", total);
smallest = smallest_value(base,n);
printf("\nThe smallest is %.2lf\n\n",smallest);
largest = largest_value(base,n);
printf("\nThe largest is %.2lf\n\n",largest);
average = total/n;
printf("\nThe average is %.2lf\n\n", average);
median =
printf("\nThe median is %.2lf\n\n", median);
var =
printf("\nThe variance is %.2lf\n\n", var);
stdeviation =
printf("\nThe standard deviation is %.2lf\n\n", stdeviation);
free(base);
free(calcarray);
}
/******************
total for array
******************/
double totalarray(double *x, int n)
{
double result = 0.0;
int i;
for (i=0; i<n; i++)
{
result = x[i] + result;
}
return(result);
}
/**********************
find smallest value
**********************/
double smallest_value(double *x, int n)
{
double result;
int i;
result = x[0];
for(i=1; i<n; i++)
{
if(x[i]<result)
result= x[i];
}
return(result);
}
/***********************
find largest value
***********************/
double largest_value(double *x, int n)
{
double result;
int i;
result = x[0];
for(i=1; i<n; i++)
{
if(x[i]>result)
result= x[i];
}
return(result);
}
/**********************
median
**********************/
double median(double *x, int n)
{
double result;
if (n%2)
{
result= x[n/2];
}
else
{
result= ((x[n/2] + x[n/2-1])/2);
}
return (result);
}
/****************
bubble sort
*****************/
void bubble(double x[], int n)
{
int i, sorted;
double temp;
sorted = 0;
while(!sorted)
{
sorted =1;
for(i=0; i<n-1; i++)
{
if(x[i]>x[i+1])
{
temp = x[i];
x[i] = x[i+1];
x[i+1] = temp;
sorted = 0;
}
}
}
}
/*****************
average array
*****************/
double average(double x[], int n)
{
double result = 0.0;
result = totalarray(x, n)/n;
return(result);
}
/**************************/
double stdeviation (double x)
{
double deviation;
deviation = sqrt(x);
return(deviation);
}
double var(double x)
{
double variance, n;
variance = totalarray(x,n)/(n-1);
return(variance);
}
*/
-
Use code tags please.
>> var = printf("\nThe variance is %.2lf\n\n", var);
What are you trying to do there? var is a function, not a variable.
>>void main
This is in the FAQ.
[edit]
Threads merged to keep things kinda tidy.
-
Your variable declarations should look similar to this:
double average,temp,total,smallest,largest,var, st_deviation, median;
Your function calls should look similar to this:
Code:
total = totalarray(base,n);
printf("\nThe total is %.2lf", total);
smallest = smallest_value(base,n);
printf("\nThe smallest is %.2lf\n\n",smallest);
largest = largest_value(base,n);
printf("\nThe largest is %.2lf\n\n",largest);
average = total/n;
printf("\nThe average is %.2lf\n\n", average);
median = find_median(base,n);
printf("\nThe median is %.2lf\n\n", median);
var = variance(base);
printf("\nThe variance is %.2lf\n\n", var);
st_deviation = stdeviation(base);
printf("\nThe standard deviation is %.2lf\n\n", st_deviation);
However a couple of your formulas are wrong.