![]() |
| | #1 |
| Guest
Posts: n/a
| There is one problem with the Part A code. When enterered my four grades they printed to the screen but not to the printer. How do I fix this? I have no clue as to how to do Part B. My brain is fried and I could use some help desperately. Can you please walk me through these instructions step by step for Part B with some examples? Part A This program will read data for one student and compute and print the student’s average. functions: 1.) get_integer - this function will be passed a character array(empty) and the maximum number of digits to be entered. The function should accept a number from the keyboard into the character array and check for input of only digits and for the maximum number. You should stay in the function until an acceptable value is entered. This function should work for an int or a long. 2.) get_average - this function will be passed an array of integer values that represents how many elements are in the array. It will return the average of these values, dropping the lowest value. The average should be rounded off to an integer value before returning it to the calling function. 1)Define the template of a data structure to contain the student's complete name, course number (itec21011101), social security number(must be a long) and four test grades(values 0 to 110), and an integer average. Define the template as a global. 2) In main define the structure variable. The program should pass a function to a pointer in the structure variable in main. The function will read in student's name, course number(itec21011101), social security number and accept the name for a max length of 20 characters, course number 11 characters and social security number for 9 digits (Use the function to get an integer with the modification to allow for exactly 9 digits.) There should be a separate function(Use the function to get an integer) to read in one grade and return it to main. This last function should be executed four times. Check each grade and make sure it is no more than three digits and the value of each grade should be 0 to 110. Each grade should be in the structure. I must use the get average function to compute the grades dropping the lowest grade. When the average is returned put in the structure average in main. Print all information to the printer with all identifying words from main. Code: #include <stdio.h>
#include <stdlib.h>
struct student {
char name[21];
char cnum[12];
long ssn;
int grades[4];
int average;
};
void get_data(struct student *);
void get_integer(char *string, int number);
int get_average(int *numbers, int number);
int main(void)
{ char string[10];
int test = 0;
int index = 0;
int flags;
struct student record;
get_data(&record);
do
{ flags = 0;
printf("\nEnter the grade %d [0-110] :", index+1);
get_integer(string, 3);
test = atoi(&string[2]);
if(test<=110 && test>0)
record.grades[index++]=test;
else
flags = 1;
}while ((flags==1)||(index < 4));
/*-- You will need to call get_average here --*/
record.average = get_average(record.grades,4);
printf("\n\nThe student's name is %s:\n",record.name);
//fprintf(stdprn,"\n\nThe student's name is %s:\n",record.name);
printf("The ssn is %ld:\n", record.ssn);
//fprintf(stdprn,"The ssn is %ld:\n", record.ssn);
printf("The course number is %s:\n", record.cnum);
//fprintf(stdprn,"The course number is %s:\n",record.cnum);
printf("The average of the four student grades is%d:\n", record.average);
//fprintf(stdprn,"The average of the four student grades is %d:\n", record.average);
return EXIT_SUCCESS;
}
void get_data(struct student *record)
{
char string1[23];
char string2[12];
char string3[13];
string1[0] = 20;
printf("Please enter the student's name: ");
cgets(string1);
strcpy(record->name, &string1[2]);
do
{ printf("\nPlease enter social security number [9DIGITS]: ");
get_integer(string2,9);
}while(string2[1]!=9);
/*-- To allow for the two count chars used by cgets --*/
/*-- we start the string copying at element 2.--*/
record->ssn=atol(&string2[2]);
string3[0]=12; /*-- Extra for the NULL char--*/
do
{ printf("\nEnter the course number [11 DIGITS]: ");
cgets(string3);
}while(string3[1]!=11);
/*-- To allow for the two count chars used by cgets--*/
/*-- we start the string copying at element 2.--*/
strcpy(record->cnum,&string3[2]);
}
void get_integer(char *string, int number)
{ int flags;
int index;
/*-- Allow for the null string terminator --*/
string[0]=number+1;
do
{ flags = 0 ;
cgets(string);
if(string[1] > number) /*-- Check input is the correct length --*/
{ printf("\nPlease re-enter [%d DIGITS]: ",number);
flags = 1;
continue;
}
/*-- To allow for the two count chars used by cgets --*/
/*-- we start the number checking from element 2.--*/
for(index=2 ; string[index] != '\0'; index++)
if (!isdigit(string[index]))
{ printf("\nOnly digits please!\n");
flags = 1;
break;
}
}while(flags == 1);
}
/*-- this function recieves the input array and size
of the array --*/
int get_average(int *numbers, int number)
{
int lowest;
float sum = 0;
int index;
int average;
for( index = 0 ; index < number ; index++)
{ if(index == 0) /*--to find the lowest set the first value in the array--*/
/*-- to the lowest variable and if a following value in the --*/
/*-- comparison is larger set it to the lowest variable--*/
lowest = numbers[0];
if(numbers[index] < lowest)
lowest = numbers[index] ;
sum += numbers[index]; /*-- sum up all the numbers--*/
}
average = (sum - lowest) / (number - 1)+ .5; /*-- get the average minus the lowest--*/
return average ; /*-- return the average as a long value --*/
}
Part B Create a menu program that will include the following: 1. Create /Add student data 2. Delete student data 3. Record/Correct student records 4. Display student records 5. Statistical Analysis 6. Quit Write a create/add function and the print function. The create/add function should open the data file as either create or add. Prompt the user to decide which way the data file is to be opened, then input student name, social security number and course number. Set all grades and average to zero. Write the structure to the file. The program is to check each field entered for the maximum size and loop until the correct data is entered. Modify the function to set all grades and the average to zero. The display function should display each student record in the file to the screen in column form. All other functions should display a message. The program should continue looping until quit is chosen. The data file to be used can be set up as an external variable or constant. The menu should be defined in an array of pointers. Write the delete function. The function should request from the user identifying information that will determine which student’s information is to be deleted. The file should stay in the order it is already in. Also add wallpaper, color shadowing the menu box, turning off the cursor and selecting from the menu by highlighting the selections. Color should be added to the functions already created. Write the update function. This function should request which grade the user wants to record for all the students at one time. (Example: The teacher has graded test 1 and wishes to record all the test 1 grades for the class). Before the file is rewritten, the user should be allowed the option of having the grades averaged at this time (use average function that drops the lowest grade). Write the statistical analysis function. The function should analyze the student averages. Print to the printer each student’s name and average. For the class print to the printer the highest average, lowest average, the average of the class and the standard deviation with identifying literals. Also print on the screen a frequency chart, in graphics mode, showing how many A, B, C, D, and F final grades. |
|
| | #2 |
| Registered User Join Date: Aug 2002
Posts: 34
| Code: thats quite funny |
| Simon is offline | |
| | #3 |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,621
| Good lord. There's no way I'm going to read all that. It'd take me all weekend. Aside from that, you really should use code tags. Read the FAQ. Aw hell, I'll show you how: [code] Your code here. [/code] Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? |
| quzah is offline | |
| | #4 |
| Lead Moderator Join Date: Aug 1998
Posts: 2,572
| ok 2 things....Basically the same as quzah said, only I'm known for being more tactful than he is.... First see if you can narrow your question down some to specifics. People arn't going to read that much. (Though I am impressed if you typed it all in). Pick one problem, ask that, solve that see if it helps. If you need more then ask later. (Though I suggest you register, people are more helpful if you do). Number 2: I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happy about helping you ![]() For example: Without code tags: for(int i=0;i<5;i++) { cout << "No code tags are bad"; } With Code Tags: Code: for(int i=0;i<5;i++)
{
cout << "This code is easy to read";
}
I've added code tags for you this time. They can be added by putting [ code ] at the beginning of your code and [ /code ] at the end, only without the spaces. More information on code tags may be found at the link in my signature. Any further questions or ways I can help please feel free to PM me. |
| kermi3 is offline | |
| | #5 | ||
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,621
| Quote:
![]() Quote:
[co[b][/b]de] [/co[b][/b]de] That way when it shows up in your post, it will actually show up as: [code] [/code] ![]() Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? | ||
| quzah is offline | |
| | #6 |
| Lead Moderator Join Date: Aug 1998
Posts: 2,572
| Yeah I know...once I quit being lazy I'll update my template heh. |
| kermi3 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| creating counters and code not working | geekrockergal | C Programming | 2 | 02-05-2009 12:50 AM |
| Grade program, pass/fail | jadedreality | C++ Programming | 2 | 12-02-2007 03:58 AM |
| Database assignment is Killing me! | Boltrig | C Programming | 2 | 11-29-2007 03:56 AM |
| Must read book! | RealityFusion | A Brief History of Cprogramming.com | 7 | 07-15-2004 09:05 PM |
| C++: Reference Book, GUI, Networking & Beyond | kuphryn | C++ Programming | 4 | 11-10-2001 08:03 PM |