IN C++ You are to write a program that will be used to look up the demographic i
ID: 3587260 • Letter: I
Question
IN C++
You are to write a program that will be used to look up the demographic information of a student.
Their are two files which I provide that contains the following information: city.dat
Numbers 1-4 are as freshman to senior in student.dat file
Preview the documentView in a new window city.dat which contains the zipcode (int), population (int), and city (string) student.dat which contains student id (int), student name (string), student classification (classification),student zipcode (int) student.datPreview the documentView in a new window ENUMS: - Create an enum named classification which contains the following data: FRESHMAN, SOPHOMORE, JUNIOR, SENIOR NAMESPACE: - Create your own namespace which contains a string array called 'myClass', which contains the following strings: "Freshman", "Sophomore", "Junior", "Senior" INPUT 1. You are to read both files into arrays (2d or 1d) (Hint: use parallel arrays) 2. The user will be prompted to enter the id of the student that they wish to look up. PROCESSING 1. You are to search through the student array(s) looking for the student whose id matches the one entered by the user. If successful, you will then attempt to look up their city demographic and ... OUTPUT 1. ... display the data to the screen. Below are test cases for you to use. Example: 1 SADDLEBACK STUDENT DEMOGRAPHIC LOOK UP ENTER STUDENT ID (-1 to Quit program) : 16 STUDENT FOUND NAME CLASSIFICATION CITY ZIPCODE POPULATION ============== ============== ===================== ======= ========== Yasuhiro Au Sophomore Costa Mesa 92617 92627 61510 The program would then pause, then after the user presses a key, clear the screen and prompt for another student all over again. Example: 2 SADDLEBACK STUDENT DEMOGRAPHIC LOOK UP ENTER STUDENT ID (-1 to Quit program) : 15 STUDENT DOES NOT EXIST IN OUR DATABASE. The program would then pause, then after the user presses a key, clear the screen and prompt for another student all over again.
in city.dat file....
92656 49046 Aliso Viejo
92808 20039 Anaheim
92807 36171 Anaheim
92806 37173 Anaheim
92802 42709 Anaheim
92801 62068 Anaheim
92805 70401 Anaheim
92804 85914 Anaheim
92823 3613 Brea
92821 35533 Brea
90621 35153 Buena Park
90620 45113 Buena Park
92624 7248 Capistrano Beach
92625 12478 Corona Del Mar
92626 49341 Costa Mesa
92627 61510 Costa Mesa
90630 47993 Cypress
92629 25756 Dana Point
92610 11248 Foothill Ranch
92708 56004 Fountain Valley
92835 24010 Fullerton
92832 24752 Fullerton
92831 34204 Fullerton
92833 51767 Fullerton
92845 16333 Garden Grove
92844 24307 Garden Grove
92841 32845 Garden Grove
92843 45214 Garden Grove
92840 54083 Garden Grove
92649 32463 Huntington Beach
92648 45317 Huntington Beach
92646 55224 Huntington Beach
92647 57245 Huntington Beach
92617 14044 Irvine
92618 16366 Irvine
92603 20184 Irvine
92606 21495 Irvine
92602 22871 Irvine
92614 24748 Irvine
92604 26853 Irvine
92612 27522 Irvine
92620 38486 Irvine
90631 67619 La Habra
90623 15554 La Palma
92694 21944 Ladera Ranch
92651 23881 Laguna Beach
92653 29291 Laguna Hills
92677 63297 Laguna Niguel
92637 16012 Laguna Woods
92630 59182 Lake Forest
90720 21751 Los Alamitos
92655 8337 Midway City
92692 47222 Mission Viejo
92691 47582 Mission Viejo
92662 2756 Newport Beach
92661 3744 Newport Beach
92663 21649 Newport Beach
92660 34797 Newport Beach
92657 9741 Newport Coast
92866 14885 Orange
92865 19704 Orange
92868 25404 Orange
92869 37184 Orange
92867 44515 Orange
92870 52033 Placentia
92688 43792 Rancho Santa Margarita
92673 29309 San Clemente
92672 34464 San Clemente
92675 34731 San Juan Capistrano
92706 36457 Santa Ana
92705 44706 Santa Ana
92701 53908 Santa Ana
92707 59492 Santa Ana
92703 65445 Santa Ana
92704 88123 Santa Ana
90740 23729 Seal Beach
92676 1945 Silverado
90680 29945 Stanton
90742 831 Sunset Beach
90743 456 Surfside
92678 494 Trabuco Canyon
92679 32611 Trabuco Canyon
92782 23032 Tustin
92780 57741 Tustin
92861 5781 Villa Park
92683 89747 Westminster
92887 20006 Yorba Linda
92886 46564 Yorba Linda
in student.dat file....
1. Zorina Abreu
1. 92656
2. Zhen Abu-Zahra
0 92808
3. Zhanetta Adeyeye
4. 92807
5. Yunzhe Afonso
0 92806
6. Youngjin Ahn
1. 92802
6 Yu Ahn
2. 92801
7 Yoon Akin-Aderibigbe
3. 92805
8 Yookyung Alexander
4. 92804
9 Yi-Shiuan Alsamdan
0 92823
10 Yingda Alter
0 92821
11 Ying Altmann
1. 90621
12 Yi-Feng Alvarez
3 90620
13 Yi Aramendia
0 92624
14 Yaya Ashkenazi
2. 92625
15 Yat-Lun Atri
3. 92626
16 Yasuhiro Au
4. 92627
17 Yanwen Aurori
5. 90630
18 Yan Austin
6. 92629
19 Ya-Han Bagdat
7. 92610
20 Yael Bala
8. 92708
You are to write a program that will be used to look up the demographic information of a student Their are two files which provide that contains the following information citydat which contains the zipcode int, population int, and city string city data student dat which contains student is intstudent name stories, student classification final student zipcode line studentdat a ENUMS: - an classification which contains the following data FRESHMAN, SOPHOMOREUNIOR SENIOR Create enum named , NAMESPACE - Create your own namespace which contains a string array called mClass, which contains the following strings: Freshman, sophomore unior senior INPUT 1. You are to read both files into arrays (2d or a Hint use parallel array 2. The user will be prompted to enter the id of the student that they wish to look up PROCESSING 1. You are to search through the student arrays looking for the student whose id matches the one entered by the user If successful, you will then attempt to look up their city demographic and OUTPUT 1 on display the data to the screen Below are test cases for you to use. Example: 1 SADDLEBACKSTUDENT DEMOGRAPHIC LOOK UP ENTER STUDENT ID (-1 to Quit program STUDENT FOUND NAME CLASSIFICATION CITY ZIPCODE POPULATION John Smith freshman Irvine 92617 14044 The program would then passes, then after the next presses a key tear the screen and prompt for another student atExplanation / Answer
#include<iostream>
#include<string>
#include <fstream>
using namespace std;
//Creates an enumerations
enum classification{ FRESHMAN, SOPHOMORE, JUNIOR, SENIOR };
//Defines a name space myClass
namespace myClass
{
//Assigns string constants to the string array
string stuClassification[] = {"Freshman", "Sophomore", "Junior", "Senior" };
}//End of name space
//Prototype declaration of Student class
class Student;
//Class City definition
class City
{
//Data member to store data
int zipcode, population;
string city;
int numberOfCity;
public:
//Prototype of member function
//Function to read city file and store data in data member
void readCity(City[]);
//Function to display city information
void displayCity(City[]);
//Friend function to search student information
friend void searchStudent(City[], Student[], int);
};//End of class
//Function to read the city.dat file
void City::readCity(City ci[])
{
//ifstream class object declared
ifstream inFile;
//Opens the city.dat file to read
inFile.open("city.dat");
int c = 0;
//Loops till end of the file
while(!inFile.eof())
{
//Read data and stores it in the data member
inFile>>ci[c].zipcode;
inFile>>ci[c].population;
getline(inFile, ci[c].city);
//Increase the record counter by one
c++;
}//End of while
//Close the file
inFile.close();
//Stores the record counter in the number of city
numberOfCity = c;
}//End of function
//Function to display city information
void City::displayCity(City ci[])
{
for(int c = 0; c < numberOfCity; c++)
cout<<" Zip code: "<<ci[c].zipcode<<" Population: "<<ci[c].population<<" City: "<<ci[c].city;
}//End of function
//Class Student definition
class Student
{
//Data member to store data
int studentId, studentZipcode;
string studentName;
classification studentClassification;
int numberOfStudent;
public:
//Prototype of member function
//Function to read student file and store the information in the data member
void readStudent(Student[]);
//Function to display all student information
void printStudent(Student[]);
//Friend function to search student information
friend void searchStudent(City[], Student[], int);
};//End of class
//Function to read student file and store the information in the data member
void Student::readStudent(Student st[])
{
//ifstream class object declared
ifstream inFile;
//Opens the student.dat file to read
inFile.open("student.dat");
int c = 0;
//Loops till end of the file
while(!inFile.eof())
{
//To store classification
int cl;
//Read file and store it in the data member
inFile>>st[c].studentId;
getline(inFile, st[c].studentName);
inFile>>cl;
//Convert integer data to enum clasification type
st[c].studentClassification = (classification)cl;
inFile>>st[c].studentZipcode;
//Increase the record counter by one
c++;
}//End of while
//Close the file
inFile.close();
//Assigns the record counter to the number of students
numberOfStudent = c;
}//End of function
//Function to display all student information
void Student::printStudent(Student st[])
{
//Loops till number of students
for(int c = 0; c < numberOfStudent; c++)
cout<<" Student ID: "<<st[c].studentId<<" Student Name: "<<st[c].studentName<<" Student Classifincation: "<<st[c].studentClassification<<" ZiPcode: "<<st[c].studentZipcode;
}//End of function
//Function to search a student record
void searchStudent(City ci[], Student st[], int id)
{
//Initially flag is set to zero
int flag = 0, c;
//Loops till number of students
for(c = 0; c < st[0].numberOfStudent; c++)
{
//Checks if the current student id is equal to given student id
if(st[c].studentId == id)
{
//Set the flag to one for record found
flag = 1;
//Come out of the loop
break;
}//End of if
}//End of for loop
//Checks if the flag value is one record found
if(flag == 1)
{
//Display student information
cout<<" Student Found ";
cout<<" Name Classification Zip Code Population";
cout<<" ----------------------------------------------------------------------------------------------------------------- ";
cout<<st[c].studentName<<" "<<myClass::stuClassification[st[c].studentClassification]<<" "<<st[c].studentZipcode<<" "<<ci[c].population<<endl;
}//End of if
//Otherwise record not found
else
cout<<" Student does not exist in our database";
}//End of function
//Main function definition
int main()
{
//Creates an array of object of City class
City cityObj[100];
//Creates an array of object of Student class
Student studentObj[100];
//To store user entered id
int id;
//Calls the function to read city file
cityObj[0].readCity(cityObj);
//Calls the function to read student file
studentObj[0].readStudent(studentObj);
cout<<"SADDLEBACK STUDENT DEMOGRAPHIC LOOK UP ";
//Loops till user enters id as -1
do
{
//Accepts student id
cout<<" ENTER STUDENT ID (-1 to Quit program): ";
cin>>id;
//Checks if id is -1
if(id == -1)
//Come out of the loop
break;
//Otherwise call the function to search id
else
searchStudent(cityObj, studentObj, id);
}while(1);//End of do - while
}//End of main function
Sample Run:
SADDLEBACK STUDENT DEMOGRAPHIC LOOK UP
ENTER STUDENT ID (-1 to Quit program): 10
Student Found
Name Classification Zip Code Population
-----------------------------------------------------------------------------------------------------------------
Yingda Alter Freshman 92821 35533
ENTER STUDENT ID (-1 to Quit program): 45
Student does not exist in our database
ENTER STUDENT ID (-1 to Quit program): 12
Student Found
Name Classification Zip Code Population
-----------------------------------------------------------------------------------------------------------------
Yi-Feng Alvarez Senior 90620 45113
ENTER STUDENT ID (-1 to Quit program): 18
Student Found
Name Classification Zip Code Population
-----------------------------------------------------------------------------------------------------------------
Yan Austin Freshman 92629 25756
ENTER STUDENT ID (-1 to Quit program): 25
Student does not exist in our database
ENTER STUDENT ID (-1 to Quit program): -1