NEED HELP..!!! C++ wikara

maxXxa

Member
Apr 14, 2010
341
5
0
Suppose you are a teacher faced with the problem of computing final grades for
all the students in one of your classes this semester. During the course of the
term, you gave four tests each worth 100 points. In addition, there was a midterm
and a final examination. Like the tests, each of these exams were out of 100
points. In addition to the tests and exams, there was a term paper also out of 100
points. The tests are worth 30% of the final grade. The midterm is worth 20%,
and the final is worth 30%. The remaining 20% of the grade is determined by the
term paper. So, a student's final average is given by the following formula:

final grade = 30% (sum of the four tests) + 20% (midterm grade) + 30% (final
exam grade) + 20% (term paper)

Finally, your have to find the final grades using the following formula.
90<= marks<= 100:::::::::::::::::::::::::::::A
87<= marks<=89::: ::::: :::::: ::::::::::::: ::::B+
80<= marks<=86:::::::::: :::::: ::::::::: ::::::B
77<= marks<=79:::::::: :::::::: :::::::: :::::::C+
70<= marks<=7 6:::::::::::::::::::::::::::::::C
67<= marks<=69:::::::::::::::::::::::::::::: D+
57<= marks<=66:::::::::::::: ::::::::::: ::::: D
0<= marks<=56:::::::::::::::::::::::::::::::::F

Your C++ program should accept the marks and then prints the final grade. Your
program is to repeat till the user enters 999.

A sample output is as follows:
, Input the grade for test #1: 78
Input the grade for test #2: 93
Input the grade for test #3: 84
Input the grade for test #4: 66
Input the grade for the midterm exam: 77
Input the grade for the final exam: 91
Input the grade for the term paper: 83
The final average is: 89.04
The final letter grade is: B+
:sorry::sorry::(:(
 

maxXxa

Member
Apr 14, 2010
341
5
0
#include<iostream>
using namespace std;
main()
{
float t1,t2,t3,t4,mid,final,term;
float avg=0.0,sum=0.0;

cout <<" Input the grade for test #1:";
cin >> t1;
cout <<" Input the grade for test #2:";
cin>>t2;
cout <<" Input the grade for test #3:";
cin>>t3;
cout <<" Input the grade for test #4:";
cin>>t4;
cout <<" Input the grade for midterm:";
cin >> mid;
cout <<" Input the grade for final:";
cin >> final;
cout <<" Input the grade for term:";
cin>>term;
 
Last edited:

maxXxa

Member
Apr 14, 2010
341
5
0
mata poddak meka start ekak aran dennakoo...me patan ganma waradida.. meeta wada variables aduwen daala meka hadanna puluwanda ... array ekak use karala kohomada karanne ...nathwath karanna puluwanda ..???

podi push ekak witharak denna ko..plzz godak pin
 

Core

Member
Jan 23, 2010
3,120
195
0
Milky Way/Local Cluster/Local Sol/Earth
//get sum of the four tests
double _fourtest= x * (30/100);

//get the midterm test
double _midterm = y * (20/100);

//get the final exam grade
double _finalgrade = z * (30/100);

//get the term paper
double _termpaper = a * (20/100);

//get the final answer
double _final = (_fourtest + _midterm + _finalgrade + _termpaper);

if( 90 <= _final && 100 >= _final)
{
//A;
}

else if(87 <= _final && 89 >= _final)
{
//B+;
}

else if(80 <= _final && 86 >= _final)
{
//B;
}

else if(77 <= _final && 79 >= _final)
{
//C+;
}

else if(70 <= _final && 76 >= _final)
{
//C;
}

else if(67 <= _final && 69>= _final)
{
//D+;
}

else if(57 <= _final && 66 >= _final)
{
//D;
}

else if(0<= _final && 56 >= _final)
{
//F;
}

else{
return "invalid";
}
 
  • Like
Reactions: koondeGoda

maxXxa

Member
Apr 14, 2010
341
5
0
Input the grade for test #1: 78
Input the grade for test #2: 93
Input the grade for test #3: 84
Input the grade for test #4: 66
Input the grade for the midterm exam: 77
Input the grade for the final exam: 91
Input the grade for the term paper: 83
The final average is: 89.04 // mata enne 155.6 ne :( :(
 

yrollgayanth

Member
Aug 26, 2008
1,524
113
0
Melbourne, AU
Machan here is a part of the code, but this is done by java. U can use same method in C++ by changing few syntax. i'll put the rest soon

Code:
package average;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        double T1, T2, T3, T4;

        // Test 1 of 30%
        System.out.print("Please enter test 1 marks :");
        T1 = in.nextDouble();


        while (T1 > 100 || T1 < 0) {
            System.out.print("Invalid.Please re-enter test 1 marks :");
            T1 = in.nextDouble();
        }

        // Test 2 of 30%
        System.out.print("Please enter test 2 marks :");
        T2 = in.nextDouble();

        while (T2 > 100 || T2 < 0) {
            System.out.print("Invalid.Please re-enter test 2 marks :");
            T2 = in.nextDouble();
        }

        //Test 3 of 30%
        System.out.print("Please enter test 3 marks :");
        T3 = in.nextDouble();


        while (T3 > 100 || T3 < 0) {
            System.out.print("Invalid.Please re-enter test 3 marks :");
            T3 = in.nextDouble();
        }

        //Test 4 of 30%
        System.out.print("Please enter test 4 marks :");
        T4 = in.nextDouble();

        while (T4 > 100 || T4 < 0) {
            System.out.print("Invalid.Please re-enter test 4 marks :");
            T4 = in.nextDouble();
        }

        // Calculate the final for 1st four tests
        double final1 = ((T1 + T2 + T3 + T4) / 4) * 0.3;

        System.out.println("Grade from first 4 tests:" + final1 + "%");


        // Mid term test
        System.out.print("Please enter mid-term test marks :");
        double midT = in.nextDouble();

        while (midT > 100 || midT < 0) {
            System.out.print("Invalid.Please re-enter mid-term marks :");
            midT = in.nextDouble();
        }

        double midTper = midT * 0.2;
        System.out.println("Mid term test percentage:" + midTper);

        // Final term test
        System.out.print("Please enter final test marks :");
        double finalT = in.nextDouble();

        while (finalT > 100 || finalT < 0) {
            System.out.print("Invalid.Please re-enter final tests marks :");
        }

        double finalper = finalT * 0.2;
        System.out.print("Final test percentage :" + finalper);



    }
}
 

maxXxa

Member
Apr 14, 2010
341
5
0
Machan here is a part of the code, but this is done by java. U can use same method in C++ by changing few syntax. i'll put the rest soon

Code:
package average;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        double T1, T2, T3, T4;

        // Test 1 of 30%
        System.out.print("Please enter test 1 marks :");
        T1 = in.nextDouble();


        while (T1 > 100 || T1 < 0) {
            System.out.print("Invalid.Please re-enter test 1 marks :");
            T1 = in.nextDouble();
        }

        // Test 2 of 30%
        System.out.print("Please enter test 2 marks :");
        T2 = in.nextDouble();

        while (T2 > 100 || T2 < 0) {
            System.out.print("Invalid.Please re-enter test 2 marks :");
            T2 = in.nextDouble();
        }

        //Test 3 of 30%
        System.out.print("Please enter test 3 marks :");
        T3 = in.nextDouble();


        while (T3 > 100 || T3 < 0) {
            System.out.print("Invalid.Please re-enter test 3 marks :");
            T3 = in.nextDouble();
        }

        //Test 4 of 30%
        System.out.print("Please enter test 4 marks :");
        T4 = in.nextDouble();

        while (T4 > 100 || T4 < 0) {
            System.out.print("Invalid.Please re-enter test 4 marks :");
            T4 = in.nextDouble();
        }

        // Calculate the final for 1st four tests
        double final1 = ((T1 + T2 + T3 + T4) / 4) * 0.3;

        System.out.println("Grade from first 4 tests:" + final1 + "%");


        // Mid term test
        System.out.print("Please enter mid-term test marks :");
        double midT = in.nextDouble();

        while (midT > 100 || midT < 0) {
            System.out.print("Invalid.Please re-enter mid-term marks :");
            midT = in.nextDouble();
        }

        double midTper = midT * 0.2;
        System.out.println("Mid term test percentage:" + midTper);

        // Final term test
        System.out.print("Please enter final test marks :");
        double finalT = in.nextDouble();

        while (finalT > 100 || finalT < 0) {
            System.out.print("Invalid.Please re-enter final tests marks :");
        }

        double finalper = finalT * 0.2;
        System.out.print("Final test percentage :" + finalper);



    }
}

thnxx bro :)
 

yrollgayanth

Member
Aug 26, 2008
1,524
113
0
Melbourne, AU
Menna final code eka habai java walin.. ei nisa Syntax wenas karanda sidda wei..me method eka use karanada, meke final answer eka hariyatama denawa

Code:
package average;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        double T1, T2, T3, T4;

        // Test 1 of 30%
        System.out.print("Please enter test 1 marks :");
        T1 = in.nextDouble();


        while (T1 > 100 || T1 < 0) {
            System.out.print("Invalid.Please re-enter test 1 marks :");
            T1 = in.nextDouble();
        }

        // Test 2 of 30%
        System.out.print("Please enter test 2 marks :");
        T2 = in.nextDouble();

        while (T2 > 100 || T2 < 0) {
            System.out.print("Invalid.Please re-enter test 2 marks :");
            T2 = in.nextDouble();
        }

        //Test 3 of 30%
        System.out.print("Please enter test 3 marks :");
        T3 = in.nextDouble();


        while (T3 > 100 || T3 < 0) {
            System.out.print("Invalid.Please re-enter test 3 marks :");
            T3 = in.nextDouble();
        }

        //Test 4 of 30%
        System.out.print("Please enter test 4 marks :");
        T4 = in.nextDouble();

        while (T4 > 100 || T4 < 0) {
            System.out.print("Invalid.Please re-enter test 4 marks :");
            T4 = in.nextDouble();
        }

        // Calculate the final of 1st four tests : 30%
        double final1 = ((T1 + T2 + T3 + T4) / 4) * 0.3;

        System.out.println("Grade from first 4 tests:" + final1 + "%");


        // Mid term test
        System.out.print("Please enter mid-term test marks :");
        double midT = in.nextDouble();

        while (midT > 100 || midT < 0) {
            System.out.print("Invalid.Please re-enter mid-term marks :");
            midT = in.nextDouble();
        }

        double midTper = midT * 0.2;
        System.out.println("Mid term test percentage:" + midTper);

        // Final term test
        System.out.print("Please enter final test marks :");
        double finalT = in.nextDouble();

        while (finalT > 100 || finalT < 0) {
            System.out.print("Invalid.Please re-enter final test marks :");
            finalT = in.nextDouble();
        }

        // Calculate the percentage of final test: 20%
        double finalper = finalT * 0.3;
        System.out.println("Final test percentage :" + finalper+"%");

    // Remaining 20% by  term paper
    System.out.print("Please enter term paper marks :");
    double termT = in.nextDouble();

    while (termT>100 || termT<0){
        System.out.print("Invalid.Please re-enter term test marks :");
        termT = in.nextDouble();
    }

    //calculate the percentage of term test: 20%
    double termper = termT*0.2;
    System.out.println("Term test percentage :"+termper+"%");

    // calculate the final percentage
    double percentage =final1 + midTper+ finalper + termper;

    System.out.println("Final percentage :"+percentage+"%");

    if (percentage>=90 && percentage <=100){
        System.out.println("Grade achieved : A");
    }
    if (percentage>=87 && percentage <=89){
        System.out.println("Grade achieved : B+");
}
    if (percentage>=80 && percentage <=86){
        System.out.println("Grade achieved : B");
}
    if (percentage>=77 && percentage <=79){
        System.out.println("Grade achieved : C+");
    }
    if (percentage>=70 && percentage <=76){
        System.out.println("Grade achieved : C");
    }
    if (percentage>=67 && percentage <=69){
        System.out.println("Grade achieved : D+");
    }
    if (percentage>=57 && percentage <=66){
        System.out.println("Grade achieved : D");
    }
    if (percentage >= 0 && percentage <= 56) {
        System.out.println("Grade achieved : F");
    }
    }
}

P.S. final "else" statement changed to "if".
 
Last edited:

Core

Member
Jan 23, 2010
3,120
195
0
Milky Way/Local Cluster/Local Sol/Earth
http://www.mediafire.com/?dilmtzzkmwn

Elakiri made me typed this more than twice ,what the hell.??
anyway your final answer is incorrect I have done it in hand the got the answer is
83.375 and I have tested the above person's answer in Java and got the same result so I assume this result should be work.!!

also remember this made for C++/CLI not for CLR ,you may need to change some codes little bit if you intend to type this on CLR

I have tested 100% and fully codes I present you ,so there should not be any mistake now.!

work well on Windows 95 to Windows 7 I guess but not sure since I didn't test on other OSs but I am pretty sure it should work cause I developed this work based on Windows Native Library files.

Notice
std::getline -> get the typed strings
::atof(); method for convert string to double


Need a help.? PM again.
;) good luck.


#include <string>
#include <iostream>

int main()
{
std::cout << "by Core for Elakiri 2010/05/06 \n";

std::string line;
double _num1,_num2,_num3,_num4,_answer,_answerFour,_midtest,_finaltest,finalGrade,_termPaper;
std::string _grade;

//get the values of four tests

std::cout << "Input the grade for test #1 \n";
std::getline(std::cin,line);
_num1 = ::atof(line.c_str());
std::cout << "Input the grade for test #1 :: " << _num1 << "\n";

std::cout << "Input the grade for test #2 \n";
std::getline(std::cin,line);
_num2 = ::atof(line.c_str());
std::cout << "Input the grade for test #2 :: " << _num2 << "\n";

std::cout << "Input the grade for test #3 \n";
std::getline(std::cin,line);
_num3 = ::atof(line.c_str());
std::cout << "Input the grade for test #3 :: " << _num3 << "\n";

std::cout << "Input the grade for test #4 \n";
std::getline(std::cin,line);
_num4 = ::atof(line.c_str());
std::cout << "Input the grade for test #4 :: " << _num4 << "\n";

_answerFour = (_num1 + _num2 + _num3 + _num4)/4; //the answer for the four tests
_answerFour = _answerFour*0.3;//the answer for the four tests

std::cout << "The overall mark for four tests " << _answerFour << "\n";
std::cout << "as a percentage " << _answerFour << "%\n";

std::cout << "********************************************" << "\n";

//mid term test
std::cout << "Input the grade for the midterm exam \n";
std::getline(std::cin,line);
_midtest = ::atof(line.c_str());
std::cout << "Input the grade for the midterm exam :: " << _midtest << "\n";
_midtest = _midtest*0.2; //the answer for the mid term test
std::cout << "Input the grade for the midterm percentage :: " << _midtest << "%\n";

//final exam
std::cout << "Input the grade for the final exam \n";
std::getline(std::cin,line);
_finaltest = ::atof(line.c_str());
std::cout << "Input the grade for the final exam :: " << _finaltest << "\n";
_finaltest = _finaltest*0.3; //the answer for the final test
std::cout << "Input the grade for the final percentage :: " << _finaltest << "%\n";

//term paper
std::cout << "Input the grade for the term paper \n";
std::getline(std::cin,line);
_termPaper = ::atof(line.c_str());
std::cout << "Input the grade for the term paper :: " << _termPaper << "\n";
_termPaper = _termPaper*0.2; //the answer for the termPaper test
std::cout << "Input the grade for the term paper percentage :: " << _termPaper << "%\n";

//get the final mark
finalGrade = _answerFour + _midtest + _finaltest + _termPaper;
std::cout << "Final Mark is :: " << finalGrade << "%\n";

if( 90 <= finalGrade && 100 >= finalGrade)
{
_grade = "A";
}

else if(87 <= finalGrade && 89 >= finalGrade)
{
_grade = "B+";
}

else if(80 <= finalGrade && 86 >= finalGrade)
{
_grade = "B";
}

else if(77 <= finalGrade && 79 >= finalGrade)
{
_grade = "C+";
}

else if(70 <= finalGrade && 76 >= finalGrade)
{
_grade = "C";
}

else if(67 <= finalGrade && 69>= finalGrade)
{
_grade = "D+";
}

else if(57 <= finalGrade && 66 >= finalGrade)
{
_grade = "D";
}

else if(0<= finalGrade && 56 >= finalGrade)
{
_grade = "F";
}

else{
std::cout << "Invalid Value \n";
}

std::cout << "Final Grade :: " << _grade << "\n";
std::cout << "Press any key to exit" << "\n";
std::getline(std::cin,line);

}