المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : calculating grades with files and arrays



C# Programming
04-11-2013, 10:24 AM
I need to calculate total grades for students with files and arrays. user first enters course they are calculating grades from. all data files use this course file as part of their name. Outer loop to read the records from the master name file. Inner loop or loop insidefunction to read the records for each student.When processing the records from a student file each one should be done separately and not assumed they are grouped in any particular order.
Program reads a record, decides what category it is in updates the running total for that category. Once the entire file has been read, you can compute the average for each category based on the number of items that should be in that category, which may be more than the number of records in the file for items turned in.

I am horrible and I mean horrible at this and I have literally put in about 35 hours into trying to make this work and this is my 8th program I have redone and really need any guidance on what I should do or if I should restart again or what I am doing wrong.

I am receiving errors on line 29 "unexpected symbol 'while' in class,struct, or interface member declaration and

line 29 and 32 "unexpected symbol ')' in class, struct or interface member declaration"

line 36 "unexpected symbol 'string',expecting 'class','delegate', 'enum',..."


using System;using System.IO;using System.Collections.Generic;using IntroCS; namespace GradeProgram { class Gradebook { static void Main() { string fileName = UIF.PromptLine ("Please enter the comp course with no spaces: "); string categoryFileName = "categories_" + fileName + ".txt"; var reader = new StreamReader (categoryFileName); while (!reader.EndOfStream) { string line = reader.ReadLine (); Console.WriteLine (line); } } string studentFileName = "student_" + fileName + ".txt"; var reader2 = new StreamReader (studentFileName); while (!reader2.EndOfStream) { string student = reader2.ReadLine (); Console.WriteLine (student); } } static string[] GetStringArray(string input) { string[] parts = input.Split(','); return parts; } static int[] GetIntArray(string input) { string[] parts = input.Split(','); int[] intparts = new int[parts.Length]; for (int i = 0; i < parts.Length; i++) intparts[i] = int.Parse(parts[i]); return intparts; } static int codeIndex(string code, string[] categories) { for (int i = 0; i < categories.Length; i++) { if (categories[i].StartsWith(code)) { return i; } } return -1; } static string[] GetCatNames(string file) { var reader = new StreamReader(file); string categories = reader.ReadLine(); string[] catnames = GetStringArray(categories); for (int i = 0; i < catnames.Length; i++) Console.WriteLine("Category at position {0} = {1}", i, catnames[i]); return catnames; } static int[] GetWeights(string file) { int targetLine = 2; int counter = 1; int[] weightvalues = new int[0]; var reader = new StreamReader(file); while (!reader.EndOfStream) { string weights = reader.ReadLine(); if (counter == targetLine) { weightvalues = GetIntArray(weights); } counter++; } for (int i = 0; i < weightvalues.Length; i++) { Console.WriteLine("Category at position {0} = {1}", i, weightvalues[i]); } return weightvalues; } static int[] GetNumOfItems(string file) { int targetLine = 3; int counter = 1; int[] itemsvalues = new int[0]; var reader = new StreamReader(file); while (!reader.EndOfStream) { string items = reader.ReadLine(); if (counter == targetLine) { itemsvalues = GetIntArray(items); } counter++; } for (int i = 0; i < itemsvalues.Length; i++) { Console.WriteLine("Category at position {0} = {1}", i, itemsvalues[i]); } return itemsvalues; } static string[] GetStudent(string file) { var reader = new StreamReader(file); //string student = reader.ReadLine(); //string[] studentnames = GetStringArray(student); //int targetLine = 3; //int counter = 1; //string[] itemsvalues = new string[0]; while (!reader.EndOfStream) { string items = reader.ReadLine(); //if (counter == targetLine) //{ string[] itemsvalues = GetStringArray(items); for (int i = 0; i < itemsvalues.Length; i++) Console.WriteLine("Category at position {0} = {1}", i, itemsvalues[i]); //} //counter++; } //return studentnames; return null; } }}