PF Assignment
PF Assignment
Task 1:
#include<iostream>
#include<fstream>
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+finalExamSc
ore)/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();
return 0;
}
Task2:
#include<iostream>
#include<fstream>
int main()
ifstream read1("word_length.txt");
ifstream read2("word_length.txt");
ofstream output("word_frequency.txt");
char max_word[100];
char word[100];
char line[100];
if (!read1)
return 1;
i = 0;
j = 0;
word[j] = line[i];
j++;
i++;
word[j] = '\0';
int k = 0;
if (j > 0)
max_length = j;
i++;
read1.close();
i = 0;
j = 0;
word[j] = line[i];
j++;
i++;
}
word[j] = '\0';
int k = 0;
if (j == max_length)
cout << word << ", " << max_length << endl;
output << word << ", " << max_length << endl;
i++;
int s = 0;
if (word[s] == '\0')
}
read2.close();
output.close();
}
Task 3:
#include<iostream>
#include<fstream>
int main()
char choice;
do {
cout << "****Employee system****" << endl;
cout << endl << "Press ‘S’: Add more 5 records in the file with existing file
format";
cout << endl << "Press ‘P’: Print all records on console";
cout << endl << "Press ‘E’: Find the employee which has max salary on the
console";
cout<< endl << "Press ‘R’: Write all the record into another file except the
one who is going to leave the depart";