Answer to Question #224665 in C++ for Penwell

Question #224665

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.


1
Expert's answer
2021-08-09T16:26:06-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS