Write a program to find the number of registered students in each semester for BIT and IT students, implemented as an array of students records. The student record has the following fields -nine digit student number, -student name, -student surname, -program registered for, -semester registered for. Assume that the above data is read from a line of a text file -"STDTA.txt". Your program should display the above information with the total number of students registered for BIT, the total number of students registered for IT, and it should also display the count of students in each semester for both BIT and IT.
#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
using namespace std;
int main(){
ifstream student("STDTA.txt");
string str;
string s2 = "BIT";
string s3 = "CourseIT";
string s4 = "semester1";
string s5 = "semester2";
string semester1[100];
string semester2[100];
int countBIT = 0;
int countIT = 0;
int semester1 = 0, semester2=0;
while(getline(student,str)){
if (str.find(s2) != std::string::npos) {
countBIT += 1;
}
if (str.find(s3) != std::string::npos) {
countIT += 1;
}
if (str.find(s4) != std::string::npos) {
semester1 += 1;
}
if (str.find(s5) != std::string::npos) {
semester2 += 1;
}
cout<<str<<"\n";
}
cout<<"The number of students registered for BIT is\t"<<countBIT<<endl;
cout<<"The number of students registered for IT is\t"<<countIT<<endl;
cout<<"The number of students in semester 1 is\t"<<semester1<<endl;
cout<<"The number of students in semester 2 is\t"<<semester2<<endl;
}
Comments
Leave a comment