Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- =^._.^= DEEEKITTY || DENISE THUY VY NGUYEN
- lab1-1.C
- PURPOSE:
- IMPLMENTED: DENISE NGUYEN //
- DATE:31/01/16 //
- USER INFORMATION: This will take MAX amount of student data:
- id, First Name, Major, Gender, and age.
- Then will ask to enter in a ID to serach.
- Display reponse and exit to find the youngest and oldest of all ///
- IMPLEMENTED METHOD: while () Yes or No will
- OVERVIEW:
- SUBPARTS:
- | .-.
- | / \ .-.
- | / \ / \ .-. .-. _ _
- +--/-------\-----/-----\-----/---\---/---\---/-\-/-\/\/---
- | / \ / \ / '-' '-'
- |/ '-' '-'
- */
- #include <iostream>
- #include <iomanip>
- #include <string>
- using namespace std;
- //struct
- struct Student
- {
- int id;
- string name;
- char gender;
- string major;
- int age;
- };
- //prototypes
- void getStuData(Student list[]);
- int findID(Student s[], int look);
- void displayStu(Student list[], int postition);
- void findYoungOld(Student s[]);
- //const array
- const int MAX=2;
- //DRIVER =^.,.^=
- int main()
- {
- Student list[MAX];
- cout << endl;
- cout << "♪ღ♪*•.¸¸¸.•*¨¨*•.¸¸¸.•*•♪ღ♪¸.•*¨¨*•.¸¸¸.•*•♪ღ♪•* ♪ღ♪\n";
- cout << "This program will take in Student data.\n";
- cout << "Serach for ID";
- cout << "Before exiting program will display the youngest and oldest age\n";
- cout << "Enjoy (。◕◡◕。)\n";
- cout << "♪ღ♪*•.¸¸¸.•*¨¨*•.¸¸¸.•*•♪ღ♪¸.•*¨¨*•.¸¸¸.•*•♪ღ♪•* ♪ღ♪\n" << endl;
- cout << "\n";
- //calling function
- getStuData(list);
- int look; //The id the user is looking for
- cout << "☁ ▅▒░☼‿☼ USE KEYBORAD FOR VALID INPUTS ☼‿☼░▒▅ ☁\n";
- cout << "Enter the ID you are looking for: ";
- cin >> look;
- //calling function
- int s;
- int i;
- int position;
- position = findID(list, look);
- if(position >= 0)
- {
- displayStu(list, position);
- }
- else
- cout << "No student with id " << look << " was found" << endl;
- cout << endl;
- findYoungOld(list);
- return 0;
- }
- //functions
- ////This function loads students' data into the array and returns the number of students.
- void getStuData(Student list[])
- {
- char answer;
- int i = 0;
- cout << "☁ ▅▒░☼‿☼ USE KEYBORAD FOR VALID INPUTS ☼‿☼░▒▅ ☁\n";
- cout << "Would you like to enter a student's information? [Y / N]: ";
- cin >> answer;
- if (answer == 'N'|| answer == 'n' )
- {
- cout << "This next part of the program will serach for endtered ID";
- cout << endl;
- }
- while ((answer == 'Y' || answer == 'y') && i < MAX)
- {
- cout << "" << endl;
- cout << "Enter in ID: ";
- cin >> list[i].id;
- cout << "Name: ";
- cin.ignore();
- getline(cin, list[i].name);
- cout << "Gender:";
- cin >> list[i].gender;
- cout << "Major: ";
- cin >> list[i].major;
- cout << "Age: ";
- cin >> list[i].age;
- i++;
- cout << endl;
- cout << "Would you like to enter a student's information? [Y / N]: ";
- cin >> answer;
- cout << endl;
- }
- Student Default = {0, " ", ' ', " ", 999};
- for(int j=0; j> MAX; j++)
- {
- s[j] = Default;
- }
- }
- //function
- /*
- This function searches through the array to find
- the student with the id the user is looking for.
- The user is asked to enter the id she is looking for in the main.
- Return the index or -1 if not found.
- */
- int findID(Student s[], int look)
- {
- int i=0;
- int postition = -1;
- bool found = false;
- while(i < MAX &&! found)
- {
- if(s[i].id == look)
- {
- found = true;
- postition = i;
- }
- i++;
- }
- return postition;
- }
- //function
- /*
- This function will be passed one student struct and display all the information (name, gender, major and age) about that student.
- */
- void displayStu(Student s[], int postition)
- {
- cout << setw(5) << "id" << setw(10) << "name" << setw(10) << "gender" << setw(10) << "";
- cout << setw(5) << "major" << setw(10) << "age" << endl;
- cout << setw(5) << "♪ღ♪*•.¸¸¸.•*¨¨*•.¸¸¸.•*•♪ღ♪¸.•*¨¨*•.¸¸¸.•*•♪ღ♪••.¸¸¸.•\n" << endl;
- cout << setw(5) << s[postition].id << setw(10) << s[postition].name << setw(10) << s[postition].gender << setw(10) << "";
- cout << setw(5) << s[postition].major << setw(10) << s[postition].age << endl;
- }
- void findYoungOld(Student s[])
- {
- int young = s[0].age;
- int old = s[0].age;
- for (int i = 1; i < MAX; i++ )
- {
- if(s[i].age < young)
- {
- clear
- young = s[i].age;
- }
- if(s[i].age > old)
- {
- old = s[i].age;
- }
- }
- cout << "The youngest age is " << young << endl;
- cout << "The oldest age is " << old << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement