The app we were taught on is visual studio 2015 with the format #include <iostre
ID: 3854454 • Letter: T
Question
The app we were taught on is visual studio 2015 with the format#include <iostream> using namespace std; Int main() { System("pause") Return 0; }
My Institution Courses Daniel Destefano Assignments Assignment-03 Assignment-03 Assignment-03 Attached Files: class dat (95 B) BinarySearch.PNG (25.941 KB) Objective Write a C++ program that reads the following information from the text file (class.dat). There could be up to 20 students. The data is given in the format given below Student-D Exam 1 Score Exam 2 Score Homework Score Final Exam Score For each student, your program should irst calculate a final grade, using this formula Final Grade 0.20 x Exam 1 0.20 Exam 2+ 0.35 Homework +0.25 Final Exam. Then assign a letter grade on the basis of 90-100-A. 80-89 " B. 70-79-C, 60-69 . D, and less than 60 F. Al the information, including the fnal grade and the letter grade, should then be displayed and wntten to a Sle Now, read the final cumulative scores into an array and do the following: Sort the array ascending-extra credit-do not require to do this Print the array backwards. Print the following on the screen an average for the score median for the score lowest score o o o highest score Note Please make sure to declare the tollowing 1 all of your variables in main 2. readFile0 function to read the data to le 3, wmeFile0 nction to write the data to Sle 4 calGrade0 function to calculate the grade that must returm letter grade 5. sotArray) function to sort the data in anay 6. printArray) unction to print the data of the array back wards & forwards 7, catAig) function to calculato merage 8 calMed) function to calculate median 9. callowesto hanction to caicuilate lowest scoe 10. calkighesto tunction to calculate highest score n addition. main shoud have nothing but variable declarations and function calls wth appropniate parameters and shouid look ike as follows
Explanation / Answer
#include<fstream.h>
#include<iomanip.h>
#include<stdio.h>
#include<conio.h>
//***************************************************************
// Student Class
//****************************************************************
class student
{
int r_no;
char name[50];
int marks_p, marks_c, marks_m, marks_e, marks_cs;
float percentage;
char grade;
void calc_grade();
public:
void getdata();
void showinfo();
void disp_tabular();
int retr_no();
}; //class ends here
void student::calc_grade()
{
percentage=(marks_p+marks_c+marks_m+marks_e+marks_cs)/5.0;
if(percentage>=60)
grade='A';
else if(percentage>=50)
grade='B';
else if(percentage>=33)
grade='C';
else
grade='F';
}
void student::getdata()
{
cout<<" Enter The roll number ";
cin>>r_no;
cout<<" Enter The Name ";
gets(name);
cout<<" Enter The marks in physics out of 100 : ";
cin>>marks_p;
cout<<" Enter The marks in chemistry out of 100 : ";
cin>>marks_c;
cout<<" Enter The marks in maths out of 100 : ";
cin>>marks_m;
cout<<" Enter The marks in english out of 100 : ";
cin>>marks_e;
cout<<" Enter The marks in computer science out of 100 : ";
cin>>marks_cs;
calc_grade();
}
void student::showinfo()
{
cout<<" Roll number of student : "<<r_no;
cout<<" Name of student : "<<name;
cout<<" Marks in Physics : "<<marks_p;
cout<<" Marks in Chemistry : "<<marks_c;
cout<<" Marks in Maths : "<<marks_m;
cout<<" Marks in English : "<<marks_e;
cout<<" Marks in Computer Science :"<<marks_cs;
cout<<" percentagecentage of student is :"<<percentage;
cout<<" Grade of student is :"<<grade;
}
void student::disp_tabular()
{
cout<<r_no<<setw(6)<<" "<<name<<setw(10)<<marks_p<<setw(4)<<marks_c<<setw(4)<<marks_m<<setw(4)
<<marks_e<<setw(4)<<marks_cs<<setw(6)<<percentage<<setw(6)<<" "<<grade<<endl;
}
int student::retr_no()
{
return r_no;
}
void write_student(); //write to file
void display_students(); //read students
void display_sp(int);
void edit_student(int);
void delete_student(int);
void class_result();
void result();
void intro();
void entry_menu();
int main()
{
char ch;
cout.setf(ios::fixed|ios::showpoint);
cout<<setprecision(2);
do
{
//clrscr();
cout<<" MAIN MENU";
cout<<" 01. RESULT MENU";
cout<<" 02. ENTRY/EDIT MENU";
cout<<" 03. EXIT";
cout<<" Please Select Your Option (1-3) ";
cin>>ch;
//clrscr();
switch(ch)
{
case '1': result();
break;
case '2': entry_menu();
break;
case '3':
break;
default :cout<<"";
}
}while(ch!='3');
return 0;
}
void write_student()
{
student st;
ofstream outFile;
outFile.open("student.dat",ios::binary|ios::app);
st.getdata();
outFile.write((char *) &st, sizeof(student));
outFile.close();
cout<<" Student record Has Been Created ";
cin.ignore();
getch();
}
void display_students()
{
student st;
ifstream inFile;
inFile.open("student.dat",ios::binary);
if(!inFile)
{
cout<<"File could not be open !! Press any Key...";
getch();
return;
}
cout<<" DISPLAY ALL RECORD !!! ";
while(inFile.read((char *) &st, sizeof(student)))
{
st.showinfo();
cout<<" ==================================== ";
}
inFile.close();
getch();
}
void display_sp(int n)
{
student st;
ifstream inFile;
inFile.open("student.dat",ios::binary);
if(!inFile)
{
cout<<"File could not be open !! Press any Key...";
getch();
return;
}
int flag=0;
while(inFile.read((char *) &st, sizeof(student)))
{
if(st.retr_no()==n)
{
st.showinfo();
flag=1;
}
}
inFile.close();
if(flag==0)
cout<<" record not exist";
getch();
}
void edit_student(int n)
{
int found=0;
student st;
fstream File;
File.open("student.dat",ios::binary|ios::in|ios::out);
if(!File)
{
cout<<"Cannot open the file !! Press any Key...";
getch();
return;
}
while(File.read((char *) &st, sizeof(student)) && found==0)
{
if(st.retr_no()==n)
{
st.showinfo();
cout<<" Please Enter The New Details of student"<<endl;
st.getdata();
int pos=(-1)*sizeof(st);
File.seekp(pos,ios::cur);
File.write((char *) &st, sizeof(student));
cout<<" Record Updated";
found=1;
}
}
File.close();
if(found==0)
cout<<" No Record Found ";
getch();
}
void delete_student(int n)
{
student st;
ifstream inFile;
inFile.open("student.dat",ios::binary);
if(!inFile)
{
cout<<"Cannot open !! Press any Key...";
getch();
return;
}
ofstream outFile;
outFile.open("Temp.dat",ios::out);
inFile.seekg(0,ios::beg);
while(inFile.read((char *) &st, sizeof(student)))
{
if(st.retr_no()!=n)
{
outFile.write((char *) &st, sizeof(student));
}
}
outFile.close();
inFile.close();
remove("student.dat");
rename("Temp.dat","student.dat");
cout<<" Record Deleted ..";
getch();
}
void class_result()
{
student st;
ifstream inFile;
inFile.open("student.dat",ios::binary);
if(!inFile)
{
cout<<"File could not be open !! Press any Key...";
getch();
return;
}
cout<<" ALL STUDENTS RESULT ";
cout<<"========================================================== ";
cout<<"R.No Name P C M E CS %age Grade"<<endl;
cout<<"========================================================== ";
while(inFile.read((char *) &st, sizeof(student)))
{
st.disp_tabular();
}
getch();
inFile.close();
}
//***************************************************************
// function to display result menu
//****************************************************************
void result()
{
char ch;
int rno;
cout<<" RESULT MENU";
cout<<" 1. Class Result";
cout<<" 2. Student Report Card";
cout<<" 3. Back to Main Menu";
cout<<" Enter Choice (1/2/3)? ";
cin>>ch;
//clrscr();
switch(ch)
{
case '1' :class_result(); break;
case '2' :cout<<" Enter Roll Number Of Student : ";
cin>>rno;
display_sp(rno); break;
case '3' :break;
default :cout<<"";
}
}
void entry_menu()
{
char ch;
int num;
//clrscr();
cout<<" MENU";
cout<<" 1.CREATE New STUDENT ";
cout<<" 2.DISPLAY STUDENT RECORDS";
cout<<" 3.SEARCH STUDENT ";
cout<<" 4.EDIT STUDENT ";
cout<<" 5.DELETE STUDENT ";
cout<<" Please Enter Your Choice (1-6) ";
cin>>ch;
//clrscr();
switch(ch)
{
case '1': write_student(); break;
case '2': display_students(); break;
case '3': cout<<" Please Enter The roll number "; cin>>num;
display_sp(num); break;
case '4': cout<<" Please Enter The roll number "; cin>>num;
edit_student(num);break;
case '5': cout<<" Please Enter The roll number "; cin>>num;
delete_student(num);break;
case '6': break;
default: cout<<""; entry_menu();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.