Pleae help me i am a beginner to computer science

In summary: Elems=infile->tell();...sets numElems to the number of elements in the answerArray, which should be 0 to 100... if(numElems>MAX_ELEMS) {...error message and quit the program} // if numElems is valid, read that many numbers from the input file, assigning to the answerArray, using another function (see 3. below) // if numElems is not valid, return 0 // call function (see 1. below) to read test answer "key"
  • #1
ayesha
3
0
Hey i am new to computer science have just started taking C classes,i got an assignment its really hard below is the question,and below that i have posted my answer what ever i have done up till now,can somebody help me fix the error and i haven't done function 3 and 5 if somebody could help me with them,and help me fix the errors in my code.any help will be appreciated,please help me as i haven't done much of arrays and files in class and this assignment is really tough for a beginner like me,i am trying my best but.please help me thank you.


Problem:
The program will be correcting a multiple-choice test using an input (text) file. The first number in the file will be how many test questions. The next line of the input file will contain several integers (possible values: 1, 2, 3, 4, or 5) for the answer key. The rest of the file will contain a student ID (4-digits) and the same number of ints as the answer key for the student's answers. You will be writing to another text file each student ID, and the student's score (number correct). After the last student is processed, you will be displaying how many students answered each test question correctly (you'll need another array of this, I'm calling it frequencyArray. In main do the following:
• Open the input file and output file (you may hard-code the filenames here). If the files don't open, print an error message and quit the program.
• Call a function (see 1. below) to read test answer "key" answerArray. This function will also give you the number of elements in the array, so save in a local variable (like numElems).
• If the answer key was read in properly (0<numElems <=100), do the following:
o Call a function (see 2. below) to process the rest of the input file (student data), using the answerArray, and writing each student ID and student's score to the output file, and filling in the frequencyArray . (continued===>)
o Call a function (see 5.below) to print numElems elements of the answerArray and frequencyArray to the output text file.
You must have the following in your program:
1. function (call from main, I'm calling readAnswerArray here) to do the following:
• Read the number of elements (numElems) for the test (once only). If numElems is valid (1 to 100) read that many numbers from the input file, assigning to the answerArray , using another function (see 3. below).
• If numElems is valid, return it in a return statement, but if numElems is not valid, return 0.
2. function (call from main, I'm calling processStudentData here) to do the following:
• Initialize all elements in the frequencyArray to 0
• print headers in the output file for "Student ID", and "Test Score"
• For each line of student data in the file (stop when you try to read a student ID, but it's the end of file):
o Read the student ID
o Read the student's test answers (I'm calling it stuAnswerArray) (use function 3. below)
o Call another function (see 4.below) to "correct" the student's answers (and update the frequencyArray)
o Print the student ID and the return value of function 3 to the output file
3. function (I'm calling readArray) that will read numElems (parameter) numbers from the text file into the array parameter.
4. function (call from processStudentData, I'm calling correctStudentAnswers here) that will compare each answerArray element to its the corresponding stuAnswerArray element, and increment the corresponding element in the frequencyArray if they match. This function will also keep a count of how many student answers are correct and return that count (in a return statement). (continued===>)
5. function (call from main, I'm calling printAnswerData) that will print to the output file, a header for each test answer, then on the next line (below each header), an answer, then below that (on the next line), each corresponding element in the frequencyArray.

DO NOT USE ANY EXTERNAL VARIABLES! You'll have to pass the arrays (declared in main) to other functions. Also, main should be mostly function and "subroutine" calls.

Include in your program:
- Arrays of ints (size of 100 for each array)
- Functions as specified above (may have more)
- Comments for program, variables and functions (use textbook's style of function comments)

Below is my code,whatever i have done uptill now,please help me fix the errors and help me with the rest of the program.

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
// for system function
#include <ctype.h>
#include <math.h>
#include <conio.h>
# define MAX_ELEMS 100;

int readAnswerArray(FILE *infile);
int processStudentData(FILE *infile,FILE *outfile,int numElems,int answerArray);
void readArray(int numElems, int answerArray);
int correctStudentAnswers(int answerArray, int stuAnswerArray,int frequencyArray);
void printAnswerData(outfile, int numElems, int answerArray,int frequencyArray);


int main(void)
{
FILE *infile;
FILE *outfile;
int numElems;
infile=fopen("inlab1.txt", "r");
outfile=fopen("outlab1.txt","w");

if(infile==NULL || outfile ==NULL )
{
printf("Cannot open file(s)--quitting program\n");
exit(1);
}

numElems=readanswerArray(infile);
processStudentData(infile,outfile,int numElems,int answerArray);
printAnswerData(outfile,int numElems, int answerArray,int frequencyArray);

system("pause");//in stdlib.h to pause run
getch();
return 0;
}

int readAnswerArray(FILE *infile)
{
int numElems;
fscanf(infile,"%d",&numElems);

if (numElems>1 && numElems <100)
readArray=answerArray[numElems];
return numElems;
else if(!(numElems>1 && numElems<100)
{
return 0;
}
else
return 1;
}

int processStudentData(FILE *infile,FILE *outfile,int numElems,int answerArray)
{
int frequencyArray[]={0};
fprintf(outfile,"%s%s",Student ID Test Score);
for(int i=0;i<MAX_ELEM &&fscanf(outfile,"%d",Student ID);i++)
readArray(stuAnswerArray);
correctStudentAnswers(int answerArray, int stuAnswerArray,int frequencyArray);
fprintf(outfile,"%d %d"Student ID stuAnswerArray);
return 0;
}

/*void readArray()
{
}*/

int correctStudentAnswers()
{
for(i=0;i<numElems;i++)
if (answerArray==stuAnswerArray)
frequencyArray++;
return ;

}

/*void printAnswerData(outfile, numElems(int), int answerArray,int frequencyArray)
{
fprintf(outfile,"%s",Problem#
*/

Thank you so much.
Take care.
Regards,
Ayesha.
 
Physics news on Phys.org
  • #2
Fix what error? What did the compiler say about the build?

It's really hard to provide help on such a large problem. If you can try your best until you get stuck on a particular error, we can try to help you find syntax or logic errors in your code.
 
  • #3
i mean do you think that my code for function 1,2 and 4 is ok?
can you give me some hint as to how to write function 3 and 5?
i am trying my best.
pleaseee help me i am a beginner.
thank you
 
  • #4
i am not even being able to read the file as it says in function 1,can you help me fix function 1 atleast?
 

FAQ: Pleae help me i am a beginner to computer science

1. What is computer science?

Computer science is a field of study that focuses on the theory, design, and applications of computers and computational systems.

2. What are the basic concepts of computer science?

Some basic concepts of computer science include algorithms, data structures, programming languages, and computer architecture.

3. How do I get started in computer science?

To get started in computer science, it is important to gain a strong foundation in mathematics, logic, and problem-solving skills. You can also take introductory courses in computer science or explore resources online.

4. What programming language should I learn first?

The programming language you should learn first depends on your goals and interests. Some popular languages for beginners include Python, Java, and C++. It is also important to learn the fundamentals of programming rather than focusing on a specific language.

5. What are the career opportunities in computer science?

The field of computer science offers a wide range of career opportunities, including software development, data analysis, cybersecurity, and artificial intelligence. With the increasing reliance on technology, the demand for computer science professionals is expected to continue to grow in the future.

Similar threads

Replies
1
Views
1K
Replies
3
Views
2K
Replies
3
Views
6K
Replies
5
Views
2K
Replies
6
Views
2K
Replies
14
Views
3K
Replies
1
Views
2K
Back
Top