Main Declares an array to store 5 GPAs and calls the 3 methods below. getData Method to read 5 student’s GPA from the keyboard computeAverage Method to compute and display average GPA lowestGPA Value returning method to determine and return the lowest GPA. * DO NOT complete everything in main(). The method main() should only declare the array and use the appropriate method calls, to the 3 other method
*IMPORTANT NOTE:*
******THE PROGRAMMING LANGUAGE IS NOT SPECIFIED IN THE QUESTION. SO WE WILL STICK ON TO C++ LANGUAGE.******
#include<iostream> using namespace std; float gpa[5]; int getData() { int i; cout<<"\nEnter the 5 GPA points\n"; for(i=0;i<5;i++) { cin>>gpa[i]; while(gpa[i]>10.0||gpa[i]<0.0) { cout<<"\nInvalid GPA\nEnter values between 0.0 to 10.0\n"; cin>>gpa[i]; } } cout<<"\n\nThe 5 GPA points are now updated as:\n"; for(i=0;i<5;i++) cout<<gpa[i]<<" "; return 0; } float computeAverage() { float avg=0; int i; for(i=0;i<5;i++) { avg=avg+gpa[i]; } avg/=5; return avg; } float lowestGPA() { float low=gpa[0]; int i; for(i=1;i<5;i++) { if(gpa[i]<low) { low=gpa[i]; } else continue; } return low; } int main() { int getData(); float computeAverage(); float lowestGPA(); getData(); cout<<"\n\nThe average of the GPAs is: "; cout<<computeAverage(); cout<<"\n\nThe lowest value of the GPAs is: "; cout<<lowestGPA(); return 0; }
Main Declares an array to store 5 GPAs and calls the 3 methods below. getData Method...
In this lab, you will create one class named ArrayFun.java which will contain a main method and 4 static methods that will be called from the main method. The process for your main method will be as follows: Declare and create a Scanner object to read from the keyboard Declare and create an array that will hold up to 100 integers Declare a variable to keep track of the number of integers currently in the array Call the fillArray method...
1) Create a main() method with a switch statement that calls either a sum() OR factorial() method, depending on what selection the user of the program makes - ask the user to enter a selection (with System.out.println()), create a Scanner then read the user's input with a call to Scanner next(), then call the appropriate method in a switch (the String that was read from the call to Scanner.next() should be what you use as your switch condition). 2) Create...
1) Create a main() method with a switch statement that calls either a sum() OR factorial() method, depending on what selection the user of the program makes - ask the user to enter a selection (with System.out.println()), create a Scanner then read the user's input with a call to Scanner next(), then call the appropriate method in a switch (the String that was read from the call to Scanner.next() should be what you use as your switch condition). 2) Create...
Lab Objectives Be able to write methods Be able to call methods Be able to declare arrays Be able to fill an array using a loop Be able to access and process data in an array Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing...
. In the method main, prompt the user for a non-negative integer and store it in an int variable num (Data validation is not required for the lab). Create an int array whose size equals num+10. Initialize the array with random integers between 0 and 50 (including 0 and excluding 50). Hint: See Topic 4 Decision Structures and File IO slides page 42 for how to generate a random integer between 0 (inclusive) and bound (exclusive) by using bound in...
Write a complete JAVA program to do the following program.
The main program calls a method to read in (from an input file) a set of people's three-digit ID numbers and their donations to a charity (hint: use parallel arrays)Then the main program calls a method to sort the ID numbers into numerical order, being sure to carry along the corresponding donations. The main program then calls a method to print the sorted 1ists in tabular form, giving both ID...
In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to design how to do it. Problem description You are given a text file called 'Students.txt' that contains information on many students. Your program reads the file, creating many Student objects, all of which will be stored into an array list of Student objects, in the Students...
You will create a program with two methods, the main() method of course and another method called printArray(). The main method will define an array of 5 elements. A loop will be used to prompt the user to enter 5 numeric values which will go into the 5 array elements. The main() method will then call the printArray() method passing the array by reference, and the array length by value. The printArray() method will then print the contents of the...
create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows. Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the command line. Use a method containing a nested for loop to compute the average of the doubles in each row. Use a method to...
In Java(using BlueJ) Purpose Purpose is to practice using file input and output, and array list of objects. Also, this lab specification tells you only what to do, you now have more responsibility to design how to do it. Problem description You are given a text file called 'Students.txt' that contains information on many students. Your program reads the file, creating many Student objects, all of which will be stored into an array list of Student objects, in the Students...