Question

In: Computer Science

The college IT department manager no longer wants to use spreadsheets to calculate grades. The manager...

The college IT department manager no longer wants to use spreadsheets to calculate grades. The manager has asked you to create a program that will input the teachers' files and output the students' grades.

Write a Ruby program named format file.rb, which can be run by typing ruby widgets.rb.

In your Ruby environment, the program must read an input file formatted in CSV format, named input.csv. Each record contains data about a student and their corresponding grades.

The data will look similar to the following:

Student Name, assignment 1, assignment 2, assignment 3, assignment 4

John Adams, 90, 91, 99, 98

Paul Newman, 90, 92, 93, 94

Mary Smith, 95, 96, 99

Be careful to follow the output format exactly, including spacing. The output of your program must look like the following:

Student Assignment Average

John Adams    94.5

Solutions

Expert Solution

Code:

require 'csv'
# Reading the userdata.csv file into an CSV Table object
student_records = CSV.read("input.csv")
# Removing the header from the CSV Table
student_records.shift
# Printing the output headers
print("Student Assignment Average\n")
# Iterating over student records
student_records.each do
  |student_data|
  # Storing the student name
  student_name = student_data[0]
  # Converting the student marks from string to int using map
  student_marks = student_data[1,student_data.size].map {|val| val.to_i}
  # Calculating the average by dividing the sum of the array with size of the array(type casted to float to get floating result)
  student_average = student_marks.sum / student_marks.size.to_f
  # Printing the name and the average rounded to 1 decimal point
  print("#{student_name} #{'%.1f' % student_average}\n")
end

Code Screenshot:

input.csv contents:

Student Name, assignment 1, assignment 2, assignment 3, assignment 4
John Adams, 90, 91, 99, 98
Paul Newman, 90, 92, 93, 94
Mary Smith, 95, 96, 99
Steve Wozniak, 91, 75, 86, 92
Russell Norvig, 85, 92, 95, 95

Output:


Related Solutions

The manager of a cosmetics section of a large department store wants to determine whether newspaper...
The manager of a cosmetics section of a large department store wants to determine whether newspaper advertising affects sales.  She randomly selects 10 items currently in stock that are priced at their usual competitive value, and she records the quantity of each item sold for a one-week period.  Then, without changing their price, she places a large ad in the newspaper, advertising the 10 items.  Again, she records the quantity sold for a one-week period.  Her data are listed below:                                 Item # Sold Before...
Your first rotation is in the Finance Department. The Finance Manager responsible for this rotation wants...
Your first rotation is in the Finance Department. The Finance Manager responsible for this rotation wants to assess your capability for controlling a department’s finances responsibly and effectively. You are given a list of journal entries coming from a bar on a cruise ship for February of this year. The descriptions and amounts are as follows: - 1st February, purchase foods from Kate’s Kitchen (new food supplier, 30 days credit) £5,001; buy wines and spirits from Harry (our long-running drinks...
A professor wants to determine whether her department should keep the requirement of college algebra as...
A professor wants to determine whether her department should keep the requirement of college algebra as a prerequisite for an Introductory Statistics course. Accordingly, she allows some students to register for the course on a pass-fail basis regardless of whether or not they have had the prerequisite. At the end of the semester, the professor compares the number of students passing or failing the class with whether or not they had algebra. Of the 70 students in the class, 30...
Imagine that you are working as manager of the Information Technology Department, ASCS College, King Saud...
Imagine that you are working as manager of the Information Technology Department, ASCS College, King Saud University, Riyadh, Saudi Arabia. Write a business letter (Alternative block format) to Sales Manager, Dell Company situated at the following address Dell Computer Corporation, One Dell Way Round Rock, Texas 78682, United States of America. Requesting them to send the price quotation of 100 workstations with the following configuration. Precision T3630;Tower Workstation; Intel Xeon E-2174G, 4 Core HT, 8MB Cache, 3.8Ghz, 4.7GHz; Windows 10...
The branch manager of a nationwide bookstore chain (located near a college campus) wants to study...
The branch manager of a nationwide bookstore chain (located near a college campus) wants to study characteristics of her store’s customers. She decides to focus on two variables: the amount of money spent by customers (on items other than textbooks) and whether the customers would consider purchasing educational DVDs related to graduate preparation exams such as the GMAT, CRE, or LSAT. The results from a sample of 70 customers are as follows: Amount spent; mean = $28.52, standard deviation =...
It was published that children who have longer first names tend to achieve higher grades (%)...
It was published that children who have longer first names tend to achieve higher grades (%) in elementary school. For example, Zai (short name, only three letters) may achieve a lower grade than Kabiralina (much longer name, ten letters). A study was conducted to investigate the influence of name length on grades from a local sixth grade class. Is there such a relationship?   NAMES GRADES Aaralyn 76 Baldasarre 72 Cai 84 Daenerys 71 Ean 74 Famke 79 Gainella 73 Hakizimana...
I'm looking to calculate grades that allows me to enter a number of grades and allows...
I'm looking to calculate grades that allows me to enter a number of grades and allows me to also calculate the average using java script collections/array list. If possible, can someone lead me in the direction on how to go about doing this with some explanation. Thank you !!! My code so far; package com.company; import java.util.*; import java.util.ArrayList; class Main { public static void main(String args[]) { Set names = new HashSet(); names.add("Christopher"); names.add("Pedro"); names.add("James"); names.add("Jess"); } }
Process Capability (Cpk and Cp) The operations manager of an insurance claims- processing department wants to...
Process Capability (Cpk and Cp) The operations manager of an insurance claims- processing department wants to determine the claims-processing capability of the department. Claims usually take a minimum of four days to handle. The company has a commitment to handle all claims within 10 days. On the average, claims are processed in eight days and processing has a standard deviation of one day. a. Compute Cp and Cpk for the claims-processing department. Based on these computations, should the claims department...
A production manager wants to assess the reactions of the blue-collar workers in his department (including...
A production manager wants to assess the reactions of the blue-collar workers in his department (including foremen) to the introduction of computer-integrated manufacturing (CIM) systems. He is particularly interested in finding out how they perceive the effects of CIM on: 1. their future as employees 2. the additional training that they will have to receive 3. future job advancement
Assume that you work for Greeble's Department Store, and your manager wants to discuss the pros...
Assume that you work for Greeble's Department Store, and your manager wants to discuss the pros and cons of discontinuing its hardware department. That department appears to be generating losses, and your manager believes that discontinuing it will increase overall store profits. Question: What factors should Greeble's management consider when trying to decide whether to discontinue its hardware department?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT