Need help on C++. Remove the duplicates from the database file sort the data by
ID: 3805001 • Letter: N
Question
Need help on C++.
Remove the duplicates from the database file sort the data by the student name first field and the student id field second in ascending order. After writing your data to the output file, output a tabular style report to standard output. Include in your report the appropriate headers for each column. You may assume that the report will print in portrait mode on a standard 8.5 x 11 sheet of paper.
Center the titles in each header. Left justify the data in each column with the exception of the floating point columns which are right justified. Floating point numbers should be displayed to two decimal places. The data should fit on in the portrait format.
(Index, student’s name, student id, address, city, state, postcode, percentage)
Student.csv
1,cristiano,333-432,add1,city1,state1,123456,87.65
2,messi,376-42l,add2,city2,state2,654321,77.43
3,cristiano,333-432,add1,city1,state1,123456,87.65
4,kaka,365-80l,add3,city3,state3,876321,91.33
Explanation / Answer
Dear Student,
Here i have written C++ program which fullfil the requirement of the given problem...
NOTE: Please note that the below program is tested on ubuntu 14.04 system and compiled under g++ compiler..
NOTE: Program is running fine and there is one formatting error, it is reading the last line twice, i do not know why..?. You copy the code and text file data in your Computer/Laptop, may be it will work fine.
-------------------------------------------------------------------------------------------------------------------------------------
Program:
-------------------------------------------------------------------------------------------------------------------------------------
#include<iostream>
#include<stdlib.h>
#include<iomanip>
#include<fstream>
#include<string.h>
using namespace std;
int main()
{
int index, id, post_code;
float percentage;
string name, address, city, state;
string line1, line2;
ifstream infile;
infile.open("Student.csv");
if(!infile)
{
cout<<"Error in reading file"<<endl;
exit(0);
}
int res;
getline(infile, line2);
while(getline(infile, line1) != NULL)
{
if(line2 != line1)
{
infile>>index>>name>>id>>address>>city>>state>>post_code>>percentage;
cout<<index<<name<<id<<address<<city<<state<<post_code<<percentage<<endl;
}
}
infile.close();
}
-----------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.