Question

Modify the program so that the credits and and scores are generated randomly for two other...

Modify the program so that the credits and and scores are generated randomly for two other students. Print the same table in requirements 1 and 2 above for each of the two students. ( RUBY)

#input number of courses
print "Enter the number of courses: "
n=gets.to_i #convert string to integer
#create array for grades, letters ,credits and gradepoints
grades=Array.new(n) #create array using new()
letters=Array.new(n)
credits=Array.new(n)
gradePoint=Array.new(n)
#run loop till number of courses
for i in 0..n-1 do
printf "Enter the grade for course %d: ",i+1
grades[i]=gets.to_f #convert string to real number
if(grades[i]>=70 && grades[i]<=100)
letters[i]='A'
gradePoint[i]=4.0
elsif(grades[i]>=60 && grades[i]<=69.99)
letters[i]='B'
gradePoint[i]=3.5
elsif(grades[i]>=50 && grades[i]<=59.99)
letters[i]='C'
gradePoint[i]=2.5
elsif(grades[i]>=40 && grades[i]<=49.99)
letters[i]='D'
gradePoint[i]=1.5
else
letters[i]='F'
gradePoint[i]=0.0
end
printf "Enter the credits for course %d: ",i+1
credits[i]=gets.to_i #convert string to int
end
printf "\n"
printf "CourseNo.\tGrade\tLetter\tCredits\n"
printf "---------\t----- ------- -------\n"
for i in 0..n-1 do
printf "%d\t\t%.1f\t%s\t%.1f\n",i+1,grades[i],letters[i],gradePoint[i]
end
#calculate weighted gpa
creditSum=0
weightedSum=0
weightedGPA=0.0
for i in 0..n-1 do
creditSum=creditSum+credits[i]
weightedSum=weightedSum+(gradePoint[i]*credits[i])
end
weightedGPA=weightedSum/creditSum
#calculate unweightedGPA
gradePointSum=0.0
for i in 0..n-1 do
gradePointSum=gradePointSum+gradePoint[i]
end
unweightedGPA=gradePointSum/n
printf "Total number of courses: %d\n",n
printf "Weighted GPA: %.2f\n",weightedGPA
printf "Unweighted GPA: %.2f\n",unweightedGPA

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

In case of any query do comment. Please rate answer as well. Thanks

Note: It was printing the data for one student, I added a loop to print data of three students now. for other two students it will generate randomly scores and credits. Please do let me know if you need any other help via comments.

Code:

#input number of courses
print "Enter the number of courses: "
n=gets.to_i #convert string to integer

#run loop to add two more student but it will not ask input from user just generate randomly
for j in 0..2 do
#create array for grades, letters ,credits and gradepoints
grades=Array.new(n) #create array using new()
letters=Array.new(n)
credits=Array.new(n)
gradePoint=Array.new(n)
#run loop till number of courses
for i in 0..n-1 do
if (j > 0)
grades[i] = Random.new.rand(1..100)
credits[i] = Random.new.rand(1..10) #you can change the range as per your credit system
else
printf "Enter the grade for course %d: ",i+1
grades[i]=gets.to_f #convert string to real number
printf "Enter the credits for course %d: ",i+1
credits[i]=gets.to_i #convert string to int
end
if(grades[i]>=70 && grades[i]<=100)
letters[i]='A'
gradePoint[i]=4.0
elsif(grades[i]>=60 && grades[i]<=69.99)
letters[i]='B'
gradePoint[i]=3.5
elsif(grades[i]>=50 && grades[i]<=59.99)
letters[i]='C'
gradePoint[i]=2.5
elsif(grades[i]>=40 && grades[i]<=49.99)
letters[i]='D'
gradePoint[i]=1.5
else
letters[i]='F'
gradePoint[i]=0.0
end
  
end
printf "\n"
printf "CourseNo.\tGrade\tLetter\tCredits\n"
printf "---------\t----- ------- -------\n"
for i in 0..n-1 do
printf "%d\t\t%.1f\t%s\t%.1f\n",i+1,grades[i],letters[i],gradePoint[i]
end
#calculate weighted gpa
creditSum=0
weightedSum=0
weightedGPA=0.0
for i in 0..n-1 do
creditSum=creditSum+credits[i]
weightedSum=weightedSum+(gradePoint[i]*credits[i])
end
weightedGPA=weightedSum/creditSum
#calculate unweightedGPA
gradePointSum=0.0
for i in 0..n-1 do
gradePointSum=gradePointSum+gradePoint[i]
end
unweightedGPA=gradePointSum/n
printf "Total number of courses: %d\n",n
printf "Weighted GPA: %.2f\n",weightedGPA
printf "Unweighted GPA: %.2f\n",unweightedGPA
end

===========screen shot of the code for indentation====

Output:

Add a comment
Know the answer?
Add Answer to:
Modify the program so that the credits and and scores are generated randomly for two other...
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
  • Question- How would I allow the program to run both upper and lower case letters. How...

    Question- How would I allow the program to run both upper and lower case letters. How would I write a switch statement for upper and lower cases to see if the value entered for Grade2 is a A or a? C programming int main() { char Grade2; float gradepoint; char Grade = 'X'; // Declares a character type variable named Grade printf("Enter a grade\t"); // Prompts for Grade scanf("%c", &Grade); // Inputs Grade printf("Grade is: \t%c\n", Grade); // Prints the...

  • C Programming: Write a program that inputs two strings that represent floating-point values, convert the strings...

    C Programming: Write a program that inputs two strings that represent floating-point values, convert the strings to double values. Calculate the sum,difference,and product of these values and print them. int main(){    // character string value array for user    char stringValue[10];       double sum=0.0;// initialize sum to store the results from 2 double values       double difference=0.0; // initialize difference to store the results from 2 double values       double product = 0.0; // intitialzie product...

  • I need some with this program, please look at the changes I need closely. Its running...

    I need some with this program, please look at the changes I need closely. Its running correctly, but I need to do a few adjustments here is the list of changes I need: 1. All of the integers on a single line, sorted in ascending order. 2. The median value of the sorted array on a single line 3. The average of the sorted array on a single line Here is the program: #include<stdio.h> #include<stdlib.h> /* This places the Adds...

  • Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a...

    Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a student's name (on one line). Then, for each course the student took last semester, the file has 2 data lines. The course name is on the first line. The second line has the student's grade average (0 to 100) and the number of credits for the course Sample data: Jon P. Washington, Jr. Computer Science I 81 4 PreCalculus 75 3 Biology I 88...

  • So I have a question in regards to my program. I'm learning to program in C...

    So I have a question in regards to my program. I'm learning to program in C and I was curious about the use of functions. We don't get into them in this class but I wanted to see how they work. Here is my program and I would like to create a function for each of my menu options. I created a function to display and read the menu and the option that is entered, but I would like to...

  • I need a basic program in C to modify my program with the following instructions: Create...

    I need a basic program in C to modify my program with the following instructions: Create a program in C that will: Add an option 4 to your menu for "Play Bingo" -read in a bingo call (e,g, B6, I17, G57, G65) -checks to see if the bingo call read in is valid (i.e., G65 is not valid) -marks all the boards that have the bingo call -checks to see if there is a winner, for our purposes winning means...

  • use c++ Weighted GPA Calculator2 Many schools factor in the number of credits each course is...

    use c++ Weighted GPA Calculator2 Many schools factor in the number of credits each course is worth, meaning a 4-credit class has more value than a 2-credit class when calculating students GPA Suppose the following were the grades for a student CreditsGrade lass Pre-Calculus History Chemistry Physical Education 1 Letter grades are assigned as follows Letter grades are worth these points 0-60 F 61 -70 D 71 80 C 81 -90 B 91 -100 A Class Pre-Calculus History Chemistr)y Physical...

  • Please help modify my C program to be able to answer these questions, it seems the...

    Please help modify my C program to be able to answer these questions, it seems the spacing and some functions arn't working as planeed. Please do NOT copy and paste other work as the answer, I need my source code to be modified. Source code: #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { char title[50]; char col1[50]; char col2[50]; int point[50]; char names[50][50]; printf("Enter a title for the data:\n"); fgets (title, 50, stdin); printf("You entered: %s\n", title);...

  • Problem Specification: Write a C++ program to calculate student’s GPA for the semester in your class. For each student, the program should accept a student’s name, ID number and the number of courses...

    Problem Specification:Write a C++ program to calculate student’s GPA for the semester in your class. For each student,the program should accept a student’s name, ID number and the number of courses he/she istaking, then for each course the following data is needed the course number a string e.g. BU 101 course credits “an integer” grade received for the course “a character”.The program should display each student’s information and their courses information. It shouldalso display the GPA for the semester. The...

  • Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the O...

    Here is a serial program in C and parallel program in OpenMP that takes in a string as input and counts the number of occurrences of a character you choose. Why is the runtime for the output for the OpenMP parallel program much longer? Serial Program #include <stdio.h> #include <string.h> #include <time.h> int main(){    char str[1000], ch;    int i, frequency = 0;    clock_t t; struct timespec ts, ts2;       printf("Enter a string: ");    gets(str);    int len = strlen(str);    printf("Enter a character...

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