Write a C program that reads N records (N could be millions) and prints to the s
ID: 3748861 • Letter: W
Question
Write a C program that reads N records (N could be millions) and prints to the screen the results of a given query The records are stored in a text file named bigdata.txt in the same folder as your program. It has N lines where N is not known upfront. Each line is a record in the format: 2, 3 or 4-words full name (family name + middle names + first name), age, weight (in kgs). A sample bigdata.txt looks like: Nguyen Van Minh 35 65.8 Tran Binh 82.1 Dao Thien Ha:i 19 53.6 Vu Dinh Toan 25 76.2 Nguyen Thi Thu Thao 28 49.5 Phan Hai Yen 58 55.3 The query is given by the user by typing in the command-line using this format: ./find from age to age from weight to weight order by age/weight] [ascending/descending] -Find all records whose age is in [35, 40] and whose weight is in [60.3, 70.8] and print them (all fields of each record satisfying the criteria) in ascending order by age, i.e. small to large age ./find 18 30 45 85.2 order by weight descending Find all records whose age is in [18, 30] and print them(all fields of each record satisfying the criteria) in descending order by weight, i.e. large to small weight. When the user types a wrong query format, the program must recognize and output this error message Wrong query format. Usage: /find from age to age from weight to _weight order by [age/weight] [ascending/descending Design requirements You must create and use suitable user-defined data types and functions in your program. In addition, you must use dynamic memory allocation where it's suitable. You must also design and implement several functions in your program instead of just having a big mainO function. Please help me coding this program, thank youExplanation / Answer
Following code works fine except the actual calculation of the average. It will take more time implement. Go through the code you will find where to write code for actual calculation.
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;
public class Database {
static String gender, race, location, college, year; //different variable declarations
public static void main(String[] args) throws Exception{ //main method
String choice = "y"; //Initialize choice to y
ArrayList list = new ArrayList(); //create object of ArrayList to store data from file
System.out.println("Enter Path : "); //ask the user to enter file path
Scanner scan = new Scanner(System.in); //create object of scanner class
String path = scan.next();
BufferedReader br=new BufferedReader( new FileReader(path)); //read file using Buffered Reader and File Reader
String currentLine; //point string each line
System.out.println("This is the data that was read from the file : "); //display the data from file
while((currentLine = br.readLine())!=null) {
System.out.println(currentLine);
String words[] = currentLine.split(" ");
for(int i=0;i<words.length;i++) {
list.add(words[i]);
}
}
System.out.println("Enter demographic data for which to find average GPA: ");
while(!choice.equalsIgnoreCase("n") ) {
int count=0;
System.out.println("Gender : (M for Male, F for Female) : ");
gender = scan.next();
System.out.println("Race/Ethnicity: (W for White, B for African/American, H for Hispanic, A for Asian, O for other ) : ");
race = scan.next();
System.out.println("Location: (R for residential, C for commuter) :");
location = scan.next();
System.out.println("College: (A for Arts and Sciences, B for Business, E for Education, N for Nursing) : ");
college = scan.next();
System.out.println("Year: (for Freshman, 2 for Sophomore, for Junior, 4 for Senior, G for Grad ) :");
year = scan.next();
System.out.println("Following students met that criteia : ");
for(int i=0; i<list.size(); i++) {
//Retrieve the students who satisfies the above criteria
}
System.out.println("Would you like to compute another (Y or N)? ");
choice = scan.next(); //alter the value of choice
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.