Question

Wk 4 - Write a Ruby Program (due Mon] Assignment Content The college IT department manager no longer wants to use spreadsheet

0 0
Add a comment Improve this question Transcribed image text
Answer #1

solution:

Given data:

Code :

require 'csv'   #required to read the data in csv file

table = CSV.parse(File.read("input.csv"), headers: true)   # reads a file input.csv and creates a table of data

puts "Student Assignment Average"   #output line as described in question
$i = 0   #will be used for iterating the table
$length = table.length()   #stores number of students in table
$assignments = table[0].length()-1   #stores number of assignments

while $i < $length do   #loop over each student record
   $j = 0  
   $sum = 0.0   #initilize sum to 0.0
   while $j < $assignments do   #loop over each assignment of a particular student
       $sum = $sum + (table[$i][$j+1]).to_f   #add the grade to sum
       $j += 1
   end
   puts table[$i][0] + " " + (($sum/$assignments).round(1)).to_s   #display name and average grade of students
   $i +=1
end

Code screenshot :

1 require csy! #required to read the data in csv file table = CSV.parse (File.read(input.csv), headers: true) # reads a fil

input file :

1 2 Student Name, assignment 1, assignment 2, assignment 3, assignment 4 John Adams, 90, 91, 99, 98 Paul Newman, 90, 92, 93,

output screenshot :

>ruby widgets.rb Student Assignment Average John Adams 94.5 Paul Newman 92.3 Mary Smith 95.0

thank you .....................

please give me thumb up

Add a comment
Know the answer?
Add Answer to:
Wk 4 - Write a Ruby Program (due Mon] Assignment Content The college IT department manager...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 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...

  • I need this in Python Please! The college IT department manager no longer wants to use...

    I need this in Python Please! 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. In your Python 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,...

  • Write a C++ program that computes student grades for an assignment as a percentage given each...

    Write a C++ program that computes student grades for an assignment as a percentage given each student's score and the total points. The final score must be rounded up to the nearest whole value using the ceil function in the <cmath header file and displayed as a percentage. You must also display the floating-point result up to 5 decimal places. You must use at least 2 functions: one to print the last name of the student and another function to...

  • In this assignment, you will write a program in C++ which uses files and nested loops...

    In this assignment, you will write a program in C++ which uses files and nested loops to create a file from the quiz grades entered by the user, then reads the grades from the file and calculates each student’s average grade and the average quiz grade for the class. Each student takes 6 quizzes (unknown number of students). Use a nested loop to write each student’s quiz grades to a file. Then read the data from the file in order...

  • Lab Exercise #15 Assignment Overview This lab exercise provides practice with Pandas data analysis library. Data...

    Lab Exercise #15 Assignment Overview This lab exercise provides practice with Pandas data analysis library. Data Files We provide three comma-separated-value file, scores.csv , college_scorecard.csv, and mpg.csv. The first file is list of a few students and their exam grades. The second file includes data from 1996 through 2016 for all undergraduate degree-granting institutions of higher education. The data about the institution will help the students to make decision about the institution for their higher education such as student completion,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT