Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

IN C++ using namespace std; (dont use classes or enums) The program would then p

ID: 3754568 • Letter: I

Question

IN C++

using namespace std;

(dont use classes or enums)

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 ("Q" to Quit program)
: vskyslv2

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.

Example: 3

SADDLEBACK STUDENT DEMOGRAPHIC LOOK UP
ENTER STUDENT ID ("Q" to Quit program)
: f0hubu1x

STUDENT FOUND

ZIP CODE DOES NOT EXIST IN OUR DATABASE

NAME                   CLASSIFICATION   CITY                                    ZIPCODE POPULATION
============== ============== ===================== ======= ==========
Bagdat Ya-Han      Junior                   **ERROR**                          99999      **ERROR**

The program would then pause, then after the user presses a key, clear the screen and prompt for another student all over again.

FINALLY: After the user quits the program, you are to print out a student report that is sorted in alphabetic order by city prior to exiting the program that prints the same demographic information as above.

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

student.dat file:

liaoibls Zorina Abreu
1 92656
gg7ygw5e Zhen Abu-Zahra
0 92808
2e47pgfa Zhanetta Adeyeye
3 92807
nl1gx1y6 Yunzhe Afonso
0 92806
4hv84xjp Youngjin Ahn
1 92802
poshch2b Yu Ahn
2 92801
bmpql2d7 Yoon Akin-Aderibigbe
3 92805
wkl0jnw3 Yookyung Alexander
2 92804
iri9s76q Yi-Shiuan Alsamdan
0 92823
dpfi0iqm Yingda Alter
0 92821
zwcr8308 Ying Altmann
1 90621
ku917ok4 Yi-Feng Alvarez
3 90620
6s6af8u0 Yi Aramendia
0 92624
103joten Yaya Ashkenazi
2 92625
9jyz5c9t Yat-Lun Atri
2 92626
mx02wdoj Yasuhiro Au
2 92627
8vxbvy85 Yanwen Aurori
2 90630
t3kk39i1 Yan Austin
2 92629
f0hubu1x Ya-Han Bagdat
2 99999
aye3aeck Yael Bala
3 92708

Explanation / Answer

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
using namespace std;
// For maximum player
#define MAX 200

// Function to read file contents and stores in respective array
void readFile(int cityZip[], int cityPopulation[], string cityName[], int *counterCity,
string studentID[], string studentName[], int studentClassification[], int studentZip[],
int *counterStudent)
{
string name;
// ifstream object declared
ifstream fRead;
// Opens the city.dat file for reading
fRead.open("city.txt");

// Checks if the file unable to open for reading display's error message with file name
if(!fRead)
{
cout<<" ERROR: Unable to open the file for reading.";
exit(0);
}// End of if condition

// Loops till end of the file
while(!fRead.eof())
{
// Reads the city zip and stores it at counterCity index position of cityZip array
fRead>>cityZip[*counterCity];
// Reads the city population and stores it at counterCity index position of cityPopulation array
fRead>>cityPopulation[*counterCity];
// Reads the city name and stores it at counterCity index position of cityName array
getline(fRead, cityName[*counterCity]);

// Increase the city counter by one
*counterCity = *counterCity + 1;
}// End of while loop
// Closes the file
fRead.close();

// Opens the file student.dat for reading
fRead.open("student.txt");

// Checks if the file unable to open for reading display's error message with file name
if(!fRead)
{
cout<<" ERROR: Unable to open the file for reading.";
exit(0);
}// End of if condition

// Loops till end of the file
while(!fRead.eof())
{
// Reads the student id and stores it at counterStudent index position of studentID array
fRead>>studentID[*counterStudent];
// Reads the student name and stores it at counterStudent index position of studentName array
getline(fRead, studentName[*counterStudent]);
// Reads the student classification and stores it at counterStudent index position of studentClassification array
fRead>>studentClassification[*counterStudent];
// Reads the student zip and stores it at counterStudent index position of studentZip array
fRead>>studentZip[*counterStudent];

// Increase the student counter by one
*counterStudent = *counterStudent + 1;
}// End of while loop
// Closes the file
fRead.close();
}// End of function

// Function to display city details
void displayCity(int cityZip[], int cityPopulation[], string cityName[], int cityCounter)
{
// Displays the heading
cout<<" ***************** City Information *****************";

// Loops till number of city record
for(int x = 0; x < cityCounter; x++)
// Displays each city information
cout<<" Zip: "<<cityZip[x]<<" Population: "<<cityPopulation[x]<<" Name: "<<cityName[x];
cout<<endl;
}// End of function

// Function to display students details
void displayStudent(string studentID[], string studentName[], int studentClassification[],
int studentZip[], int studentCounter)
{
// Displays the heading
cout<<" ***************** Student Information *****************";

// Loops till number of student record
for(int x = 0; x < studentCounter; x++)
// Displays each student information
cout<<" ID: "<<studentID[x]<<" Name: "<<studentName[x]
<<" Classification: "<<studentClassification[x]<<" ZIP: "<<studentZip[x];
cout<<endl;
}// End of function

void searchData(int cityZip[], int cityPopulation[], string cityName[], int counterCity,
string studentID[], string studentName[], int studentClassification[], int studentZip[],
int counterStudent)
{
// To store student entered by the user
string id;
// To store the found status of city and student
int foundStu, foundCity;

// Loops till user entered id is not "Q"
do
{
// Displays message
cout<<" SADDLEBACK STUDENT DEMOGRAPHIC LOOK UP "
<<" ENTER STUDENT ID ("Q" to Quit program) : ";
// Accepts student id
cin>>id;

// Checks if id is "Q" then stop
if(id.compare("Q") == 0)
break;

// Initialize student and city found status to -1 for not found
foundStu = -1;
foundCity = -1;

// Loops till number of students record
for(int x = 0; x < counterStudent; x++)
{
// Checks if user entered student id is equals to current index position student id
if(id.compare(studentID[x]) == 0)
{
// Update the found status to loop variable as found index position
foundStu = x;
// Come out of the loop
break;
}// End of if condition
}// End of for loop

// Loops till number of city record
for(int y = 0; y < counterCity; y++)
{
// Checks students found index position zip is equals to current index position city zip
if(studentZip[foundStu] == cityZip[y])
{
// Update the found status to loop variable as found index position
foundCity = y;
// Come out of the loop
break;
}// End of if condition
}// End of for loop

// Checks if student found status is -1 then display the following message
if(foundStu == -1)
cout<<" STUDENT DOES NOT EXIST IN OUR DATABASE.";
// Otherwise checks if city found status is -1 then display the following message
else if(foundCity == -1)
cout<<" STUDENT FOUND ZIP CODE DOES NOT EXIST IN OUR DATABASE";

// Checks if both the student and city found status is greater than or equals to 0
// then both student and city record found
if(foundStu >= 0 && foundCity >= 0)
{
// Displays the heading
cout<<" NAME CLASSIFICATION CITY ZIPCODE POPULATION ";
cout<<"--------------------------------------------------------------------------------- ";

// Displays the information
cout<<studentName[foundStu]<<" "<<studentClassification[foundStu]<<" "<<cityName[foundCity]
<<" "<<studentZip[foundStu]<<" "<<cityPopulation[foundCity]<<endl;
}// End of if condition

// Checks if the student found status is greater than or equals to 0
// and city found status is -1 then student record found but city record not found
else if(foundStu >= 0 && foundCity == -1)
{
// Displays the heading
cout<<" NAME CLASSIFICATION CITY ZIPCODE POPULATION ";
cout<<"--------------------------------------------------------------------------------- ";

// Displays the information
cout<<studentName[foundStu]<<" "<<studentClassification[foundStu]<<" **ERROR** "
<<" "<<studentZip[foundStu]<<" **ERROR** "<<endl;
}// End of else if condition
}while(1); // End of do - while loop
}// End of function

// main function definition
int main()
{
// Declares record counter for city and student
int cityCounter = 0, studentCounter = 0;

// Declares array of size MAX for city and student
int cityZip[MAX], cityPopulation[MAX], studentClassification[MAX], studentZip[MAX];
string cityName[MAX], studentID[MAX], studentName[MAX];

// Calls the function to read city and student file contents and stores it in respective array
readFile(cityZip, cityPopulation, cityName, &cityCounter, studentID, studentName, studentClassification,
studentZip, &studentCounter);

// Calls the function to display city details
displayCity(cityZip, cityPopulation, cityName, cityCounter);

// Calls the function to display student details
displayStudent(studentID, studentName, studentClassification, studentZip, studentCounter);

// Calls the function to search and display found city and student information
searchData(cityZip, cityPopulation, cityName, cityCounter, studentID, studentName, studentClassification,
studentZip, studentCounter);
}// End of main function

Sample Output:


***************** City Information *****************
Zip: 92656 Population: 49046 Name: Aliso Viejo
Zip: 92808 Population: 20039 Name: Anaheim
Zip: 92807 Population: 36171 Name: Anaheim
Zip: 92806 Population: 37173 Name: Anaheim
Zip: 92802 Population: 42709 Name: Anaheim
Zip: 92801 Population: 62068 Name: Anaheim
Zip: 92805 Population: 70401 Name: Anaheim
Zip: 92804 Population: 85914 Name: Anaheim
Zip: 92823 Population: 3613 Name: Brea
Zip: 92821 Population: 35533 Name: Brea
Zip: 90621 Population: 35153 Name: Buena Park
Zip: 90620 Population: 45113 Name: Buena Park
Zip: 92624 Population: 7248 Name: Capistrano Beach
Zip: 92625 Population: 12478 Name: Corona Del Mar
Zip: 92626 Population: 49341 Name: Costa Mesa
Zip: 92627 Population: 61510 Name: Costa Mesa
Zip: 90630 Population: 47993 Name: Cypress
Zip: 92629 Population: 25756 Name: Dana Point
Zip: 92610 Population: 11248 Name: Foothill Ranch
Zip: 92708 Population: 56004 Name: Fountain Valley
Zip: 92835 Population: 24010 Name: Fullerton
Zip: 92832 Population: 24752 Name: Fullerton
Zip: 92831 Population: 34204 Name: Fullerton
Zip: 92833 Population: 51767 Name: Fullerton
Zip: 92845 Population: 16333 Name: Garden Grove
Zip: 92844 Population: 24307 Name: Garden Grove
Zip: 92841 Population: 32845 Name: Garden Grove
Zip: 92843 Population: 45214 Name: Garden Grove
Zip: 92840 Population: 54083 Name: Garden Grove
Zip: 92649 Population: 32463 Name: Huntington Beach
Zip: 92648 Population: 45317 Name: Huntington Beach
Zip: 92646 Population: 55224 Name: Huntington Beach
Zip: 92647 Population: 57245 Name: Huntington Beach
Zip: 92617 Population: 14044 Name: Irvine
Zip: 92618 Population: 16366 Name: Irvine
Zip: 92603 Population: 20184 Name: Irvine
Zip: 92606 Population: 21495 Name: Irvine
Zip: 92602 Population: 22871 Name: Irvine
Zip: 92614 Population: 24748 Name: Irvine
Zip: 92604 Population: 26853 Name: Irvine
Zip: 92612 Population: 27522 Name: Irvine
Zip: 92620 Population: 38486 Name: Irvine
Zip: 90631 Population: 67619 Name: La Habra
Zip: 90623 Population: 15554 Name: La Palma
Zip: 92694 Population: 21944 Name: Ladera Ranch
Zip: 92651 Population: 23881 Name: Laguna Beach
Zip: 92653 Population: 29291 Name: Laguna Hills
Zip: 92677 Population: 63297 Name: Laguna Niguel
Zip: 92637 Population: 16012 Name: Laguna Woods
Zip: 92630 Population: 59182 Name: Lake Forest
Zip: 90720 Population: 21751 Name: Los Alamitos
Zip: 92655 Population: 8337 Name: Midway City
Zip: 92692 Population: 47222 Name: Mission Viejo
Zip: 92691 Population: 47582 Name: Mission Viejo
Zip: 92662 Population: 2756 Name: Newport Beach
Zip: 92661 Population: 3744 Name: Newport Beach
Zip: 92663 Population: 21649 Name: Newport Beach
Zip: 92660 Population: 34797 Name: Newport Beach
Zip: 92657 Population: 9741 Name: Newport Coast
Zip: 92866 Population: 14885 Name: Orange
Zip: 92865 Population: 19704 Name: Orange
Zip: 92868 Population: 25404 Name: Orange
Zip: 92869 Population: 37184 Name: Orange
Zip: 92867 Population: 44515 Name: Orange
Zip: 92870 Population: 52033 Name: Placentia
Zip: 92688 Population: 43792 Name: Rancho Santa Margarita
Zip: 92673 Population: 29309 Name: San Clemente
Zip: 92672 Population: 34464 Name: San Clemente
Zip: 92675 Population: 34731 Name: San Juan Capistrano
Zip: 92706 Population: 36457 Name: Santa Ana
Zip: 92705 Population: 44706 Name: Santa Ana
Zip: 92701 Population: 53908 Name: Santa Ana
Zip: 92707 Population: 59492 Name: Santa Ana
Zip: 92703 Population: 65445 Name: Santa Ana
Zip: 92704 Population: 88123 Name: Santa Ana
Zip: 90740 Population: 23729 Name: Seal Beach
Zip: 92676 Population: 1945 Name: Silverado
Zip: 90680 Population: 29945 Name: Stanton
Zip: 90742 Population: 831 Name: Sunset Beach
Zip: 90743 Population: 456 Name: Surfside
Zip: 92678 Population: 494 Name: Trabuco Canyon
Zip: 92679 Population: 32611 Name: Trabuco Canyon
Zip: 92782 Population: 23032 Name: Tustin
Zip: 92780 Population: 57741 Name: Tustin
Zip: 92861 Population: 5781 Name: Villa Park
Zip: 92683 Population: 89747 Name: Westminster
Zip: 92887 Population: 20006 Name: Yorba Linda
Zip: 92886 Population: 46564 Name: Yorba Linda

***************** Student Information *****************
ID: liaoibls Name: Zorina Abreu Classification: 1 ZIP: 92656
ID: gg7ygw5e Name: Zhen Abu-Zahra Classification: 0 ZIP: 92808
ID: 2e47pgfa Name: Zhanetta Adeyeye Classification: 3 ZIP: 92807
ID: nl1gx1y6 Name: Yunzhe Afonso Classification: 0 ZIP: 92806
ID: 4hv84xjp Name: Youngjin Ahn Classification: 1 ZIP: 92802
ID: poshch2b Name: Yu Ahn Classification: 2 ZIP: 92801
ID: bmpql2d7 Name: Yoon Akin-Aderibigbe Classification: 3 ZIP: 92805
ID: wkl0jnw3 Name: Yookyung Alexander Classification: 2 ZIP: 92804
ID: iri9s76q Name: Yi-Shiuan Alsamdan Classification: 0 ZIP: 92823
ID: dpfi0iqm Name: Yingda Alter Classification: 0 ZIP: 92821
ID: zwcr8308 Name: Ying Altmann Classification: 1 ZIP: 90621
ID: ku917ok4 Name: Yi-Feng Alvarez Classification: 3 ZIP: 90620
ID: 6s6af8u0 Name: Yi Aramendia Classification: 0 ZIP: 92624
ID: 103joten Name: Yaya Ashkenazi Classification: 2 ZIP: 92625
ID: 9jyz5c9t Name: Yat-Lun Atri Classification: 2 ZIP: 92626
ID: mx02wdoj Name: Yasuhiro Au Classification: 2 ZIP: 92627
ID: 8vxbvy85 Name: Yanwen Aurori Classification: 2 ZIP: 90630
ID: t3kk39i1 Name: Yan Austin Classification: 2 ZIP: 92629
ID: f0hubu1x Name: Ya-Han Bagdat Classification: 2 ZIP: 99999
ID: aye3aeck Name: Yael Bala Classification: 3 ZIP: 92708

SADDLEBACK STUDENT DEMOGRAPHIC LOOK UP
ENTER STUDENT ID ("Q" to Quit program)
: liaoibls

NAME CLASSIFICATION CITY ZIPCODE POPULATION
---------------------------------------------------------------------------------
Zorina Abreu 1 Aliso Viejo 92656 49046

SADDLEBACK STUDENT DEMOGRAPHIC LOOK UP
ENTER STUDENT ID ("Q" to Quit program)
: vskyslv2

STUDENT DOES NOT EXIST IN OUR DATABASE.
SADDLEBACK STUDENT DEMOGRAPHIC LOOK UP
ENTER STUDENT ID ("Q" to Quit program)
: f0hubu1x

STUDENT FOUND
ZIP CODE DOES NOT EXIST IN OUR DATABASE
NAME CLASSIFICATION CITY ZIPCODE POPULATION
---------------------------------------------------------------------------------
Ya-Han Bagdat 2 **ERROR** 99999 **ERROR**

SADDLEBACK STUDENT DEMOGRAPHIC LOOK UP
ENTER STUDENT ID ("Q" to Quit program)
: Q