Question

4. Design a for loop that would add all the odd numbers starting from 1 to 1001 and store in the variable sum (10 points) 5.

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

4) For this question we would write a For loop that would start with 1 and it would run till 1001 and we will check if number is odd.

int sum=0;

for (int i=1;i <= 1001;i++){

if(i%2 !=0){

sum=sum+i;

}

}

5) Here I am writing this code using Java language. In this code we will write a Method called Grade that would be called from main.

Class Score{

public int average {get;set;}

public string grade{get;set;}

public Score(int average,string grade){

this.average=average;

this.grade=grade;

}

public static void main(String[] args){

Score sc=Score(30,50,70);

System.out.println("Average is : "+sc.average + " grade is : " +sc.grade);

}

public static Score Grade(int homeworks , int midterm , int final){

int total = (homeworks*20/100)+(midterm*30/100)+(final*50/100);

int average=total/3 ;

string grade="";

if(average>=90){

grade="A";

}else if(average >=80){

grade="B";

}else if(average >=70){

grade="C";

}else{

grade="F";

}

Score obj=new Score(average,grade);

return obj;

}

Add a comment
Know the answer?
Add Answer to:
english 4. Design a for loop that would add all the odd numbers starting from 1...
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
  • Write a grading program in Java for a class with the following grading policies: There are...

    Write a grading program in Java for a class with the following grading policies: There are three quizzes, each graded on the basis of 10 points. There is one midterm exam, graded on the basis of 100 points. There is one final exam, graded on the basis of 100 points. The final exam counts for 40% of the grade. The midterm counts for 35% of the grade. The three quizzes together count for a total of 25% of the grade....

  • using if/switch statements (C++) Write a grading program for a class with the following grading policies:...

    using if/switch statements (C++) Write a grading program for a class with the following grading policies: There are two quizzes, each graded on the basis of 10 points There is one midterm exam and one final exam, each graded on the basis of 100 points The final exam counts for 50% of the grade, the midterm counts for 25% and the two quizzes together count for a total of 25%. (Do not forget to normalize the quiz scores. They should...

  • using C geany. Please Dr. exercise # 1 and 2 During the lab: PART I: PROGRAMMING...

    using C geany. Please Dr. exercise # 1 and 2 During the lab: PART I: PROGRAMMING EXERCISES a. Using Geany, write a C program that prompts and asks the user for two assignment marks (al and a2) and two test marks (ti and t2). All four variables are integer variables and are in % (out of 100). You program should display the four marks properly lalebed to check if the input has been successful. b. Next, calculate and display the...

  • c++ implement a student class Determine the final scores, letter grades, and rankings of all students...

    c++ implement a student class Determine the final scores, letter grades, and rankings of all students in a course. All records of the course will be stored in an input file, and a record of each student will include the first name, id, five quiz scores, two exam scores, and one final exam score. For this project, you will develop a program named cpp to determine the final scores, letter grades, and rankings of all students in a course. All...

  • Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment...

    Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and total points. The final score must be rounded up to the nearest whole value using the ceil function in the <cmath> header file. You must also display the floating-point result up to 5 decimal places. The input to the program must come from a file containing a single line with the score and total separated by...

  • (Statistics) a. Write a C++ program that reads a list of double-precision scores from the keyboard...

    (Statistics) a. Write a C++ program that reads a list of double-precision scores from the keyboard into an array named scores. It is assumed that the user will enter no more than 35 scores. The scores are to be counted as they're read, and entry is to be terminated when a negative value has been entered. After all scores have been input, your program should find and display the sum and average of the scores. The scores should then be...

  • CIS 120 Final Project Case Study Grades Analysis 1. 4. Overview Please use the Excel data...

    CIS 120 Final Project Case Study Grades Analysis 1. 4. Overview Please use the Excel data file to analyze the grades for students in their class. You are required to use either a formula or function to receive points for the steps. Typing in the answer is worth 0 (zero) points. Steps to complete are as following: Separate the student first name and last name into two columns. (5 points) 2. Get the Average, Minimum, and Maximum of Test 1....

  • c++ O fe/C/Users/Younis/App ft.Microsoftedgc b17%20(1)pdf 1 of 1 CSC 2000 C+t Programming Language Winter Term 2019...

    c++ O fe/C/Users/Younis/App ft.Microsoftedgc b17%20(1)pdf 1 of 1 CSC 2000 C+t Programming Language Winter Term 2019 Lab 17 10 points Due in Lab Write a C++program that inputs 15 real numbers into a three by five two- dimensional array; also write a function that determines the total number of values in these ranges: less than 60, greater than or equal to 60 and less than 70, greater than or equal to 70 and less than 80, greater than or equal...

  • ASSIGNMENT #3 ** using System; namespace GradeCalculatorNew {    class MainClass    {        public...

    ASSIGNMENT #3 ** using System; namespace GradeCalculatorNew {    class MainClass    {        public static void Main (string[] args)        {            int test1,test2,test3;            double average,average2;            char letterGrade;            Console.WriteLine("Enter test score1");            test1=Convert.ToInt32(Console.ReadLine());            Console.WriteLine("Enter test score2");            test2=Convert.ToInt32(Console.ReadLine());            Console.WriteLine("Enter test score3");            test3=Convert.ToInt32(Console.ReadLine());            average=(test1+test2+test3)/3.0;            average=(int)(average+0.5);           ...

  • Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate...

    Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...

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
ADVERTISEMENT