0% found this document useful (0 votes)
10 views2 pages

Pftask 1

This C++ program reads student data from a file named 'students.txt', calculates their total percentage based on scores from assignments, quizzes, midterms, and final exams, and writes the results to 'grades.txt'. It assigns letter grades based on the calculated percentage. If the input file cannot be opened, an error message is displayed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Pftask 1

This C++ program reads student data from a file named 'students.txt', calculates their total percentage based on scores from assignments, quizzes, midterms, and final exams, and writes the results to 'grades.txt'. It assigns letter grades based on the calculated percentage. If the input file cannot be opened, an error message is displayed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<iostream>

#include<fstream>
using namespace std;
int main()
{
ifstream inputFile("students.txt");
ofstream outputFile("grades.txt");
if(!inputFile)
{
cout<<"Error"<<endl;
return 1;
}
char studentName[50],studentID[20];
float assignmentScore,quizScore,midtermScore,finalExamScore;
float totalPercentage;
while(inputFile.getline(studentName,50,','))
{
inputFile>>ws;
inputFile.getline(studentID,50,',');
inputFile>>assignmentScore;
inputFile.ignore();
inputFile>>quizScore;
inputFile.ignore();
inputFile>>midtermScore;
inputFile.ignore();
inputFile>>finalExamScore;
inputFile.ignore();
totalPercentage=((assignmentScore+quizScore+midtermScore+finalExamScore)/
115.0)*100.0;
outputFile<<studentName<<","<<studentID<<","<<totalPercentage<<",";
if(totalPercentage>=85&&totalPercentage<=100)
{
outputFile<<"A";
}
else if(totalPercentage>=80&&totalPercentage<=84)
{
outputFile<<"A-";
}
else if(totalPercentage>=75&&totalPercentage<=79)
{
outputFile<<"B+";
}
else if(totalPercentage>=70&&totalPercentage<=74)
{
outputFile<<"B";
}
else if(totalPercentage>=65&&totalPercentage<=69)
{
outputFile<<"B-";
}
else if(totalPercentage>=60&&totalPercentage<=64)
{
outputFile<<"C+";
}
else if(totalPercentage>=56&&totalPercentage<=59)
{
outputFile<<"C";
}
else if(totalPercentage>=50&&totalPercentage<=54)
{
outputFile<<"C-";
}
else if(totalPercentage<50)
{
outputFile<<"F";
}
outputFile<<endl;
}
inputFile.close();
outputFile.close();
cout<<"Grade calculation completed."<<endl;
return 0;
}

You might also like