Write a program that reads marks of 100 students from the file specified by user (Read Input filename from user), and print highest and lowest marks in the second file specified by user (Read Output filename from user). (15)
For Example:
#include<iostream> #include<fstream> using namespace std; int main() { ifstream ifs; ofstream ofs; int marks[100]; int imarks; char filename[20]; cout<<"Enter a file name :"; cin>>filename; ifs.open(filename); ofs.open("result.txt"); for(int i=0;i<20;i++) { ifs>>imarks; marks[i]=imarks; } int largest=marks[0]; for(int i=0;i<20;i++) if(marks[i]>largest) largest=marks[i]; int smallest=marks[0]; for(int i=0;i<20;i++) if(marks[i]<smallest) smallest=marks[i]; ofs<<"Highest marks is :"<<largest; ofs<<"\nLowest marks is :"<<smallest; cout<<"File Create Successfully!!"; ofs.close(); ifs.close(); return(0); }
0 comments:
Post a Comment