please make sure the code is in c++ I have attached the CS material .. I have al
ID: 3548762 • Letter: P
Question
please make sure the code is in c++
I have attached the CS material .. I have also attached with sample input. YOu are suppose to read the file in a function, write a function for the average of each student, function for average of each course, function for min and max of each course and function fro printing the information out. There will total be 5 function (optimal). Please try to do it as much as you can. If you want to change few requirements, make an assumption and go for it but atleast attempt to solve it.
Explanation / Answer
Did the first and last part. For rest concept will be same
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
public class SchoolReport
{
static LinkedList<String> firstName = new LinkedList<String>();
static LinkedList<String> lastName = new LinkedList<String>();
static LinkedList<String> mathsMarks = new LinkedList<String>();
static LinkedList<String> physicsMarks = new LinkedList<String>();
static LinkedList<String> chemistryMarks = new LinkedList<String>();
static int[] markSheet;
static String[] firstNameArr;
static String[] lastNameArr;
public static void main(String args[]) throws IOException, NullPointerException
{
String word = null;
int lineNo = 0;
File file = new File("C://Users//Rakesh//SkyDrive//Documents//test.txt");
try(BufferedReader br = new BufferedReader(new FileReader(file)))
{
String sCurrentLine;
while((sCurrentLine = br.readLine().trim()) != null)
{
lineNo ++;
StringTokenizer sf = new StringTokenizer(sCurrentLine); // Has a single word
LinkedList<String> temps = new LinkedList<String>();
while (sf.hasMoreTokens())
{
word = sf.nextToken();
temps.add(word);
}
for (String b: temps)
System.out.print(b + " ");
System.out.println();
if (lineNo != 1)
{
String[] tempsArray = (String[]) temps.toArray(new String[temps.size()]);
for (int i = 0; i < tempsArray.length; i++)
{
firstName.add(tempsArray[1]);
lastName.add(tempsArray[2]);
mathsMarks.add(tempsArray[3]);
physicsMarks.add(tempsArray[4]);
chemistryMarks.add(tempsArray[5]);
}
}
}
firstNameArr = (String[]) firstName.toArray(new String[firstName.size()]);
lastNameArr = (String[]) lastName.toArray(new String[lastName.size()]);
averageStudent();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public static void averageStudent()
{
markSheet = new int[mathsMarks.size()];
String[] mathsMarksArr = (String[]) mathsMarks.toArray(new String[mathsMarks.size()]);
String[] physicsMarksArr = (String[]) physicsMarks.toArray(new String[physicsMarks.size()]);
String[] chemistryMarksArr = (String[]) chemistryMarks.toArray(new String[chemistryMarks.size()]);
for (int i = 0; i < mathsMarks.size(); i++)
{
markSheet[i] = Integer.parseInt(mathsMarksArr[i]) + Integer.parseInt(physicsMarksArr[i]) + Integer.parseInt(chemistryMarksArr[i]);
System.out.print(firstNameArr[i] + " " + lastNameArr[i] + " " + markSheet[i]/mathsMarks.size());
}
System.out.println();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.