LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-19-2016, 03:39 PM   #1
ekincaid2002
LQ Newbie
 
Registered: Mar 2016
Posts: 12

Rep: Reputation: Disabled
Having issues with serial search.


if i only enter 1 set of records i get a correct return but if i enter more than one set of record it only reconizes the last set. so when i search for student id the only one thats in the file that works correctly and displays the correct output is the last studentid entered rest dont work properly

Code:
oid loadarray() {
	fin.open("E:\\studentidarray.txt");
	
	string word;
	vector<string> myWords;
	while (fin >> word)
	{
		myWords.push_back(word);
		
	}
	fin.close();
	
}



void search_data()
{
	match = 'N';
	row = 0;
	maxsize = 8;

	cout << " enter a student id to be searched:    ";
	cin >> students;
									

	while (match == 'N' && row < maxsize)
	{
		if (students == studentid)
		{
			match = 'Y';
		}
		else
		{
			row = row + 1;
		}

		if (match == 'Y')
		{
			sucessful();
		}
		else
		{
			unsucessful();
		}
	}

			cout << " Another Search? ";
			cin >> moresearch;
			moresearch = toupper(moresearch);

	while (moresearch != 'Y' && moresearch != 'N')
		{
			cout << " Error ";
			cout << " Please enter Y or N as a response ";
			cin >> moresearch;
			moresearch = toupper(moresearch);
		}
	if (moresearch == 'Y')
		{
			search_data();
		}
}

void sucessful()
{
	cout << "student was found!" << endl << endl;
	if (gpa >= 3.65)
	{
		cout << firstname << " " << lastname << " " << "is on the Dean's List." << endl;
	}
	if(gpa >= 2.0 || gpa < 3.65)
	{
		cout << firstname << " " << lastname << " " << "is an average student." << endl;
	}
	if (gpa < 2.0)
	{
		cout << firstname << " " << lastname << " " << "is on Academic Probation." << endl;
	}


}
void unsucessful()
{
	cout << "Student ID was not found" << endl;
	;
}

Last edited by ekincaid2002; 03-19-2016 at 03:44 PM.
 
Old 03-19-2016, 04:12 PM   #2
ekincaid2002
LQ Newbie
 
Registered: Mar 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
in otherwords seems like its not starting at the first line each search feel like its starting at the last line and acting like the rest are invalid because its starting at the end line.

Last edited by ekincaid2002; 03-19-2016 at 04:18 PM.
 
Old 03-19-2016, 06:59 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
What type of variable is studentid? How is it being assigned?

Please post your entire program.
 
Old 03-20-2016, 08:49 AM   #4
ekincaid2002
LQ Newbie
 
Registered: Mar 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
Code:
/*
Variable								Represents

firstname								First Name
lastname								Last Name
studentid								Student ID
gpa										Grade point average
match									search match
morerecords								More entries for file
moresearch								Reply for additional searches
reply									User Response
row										row of array
maxsize									Max size of array
students								target student in array

*/

#include <vector>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
ifstream fin;
ofstream fout;

double studentid, students, gpa, row, maxsize;
char reply, match, wait, moresearch;
string firstname, lastname;


void build();
void loadarray();
void search_data();
void sucessful();
void unsucessful();

int main()
{
	system("cls");
	cout << "  Student Academic Standing  " << endl;
	cout << "Is this the correct program? (Y/N) ";
	cin >> reply;
	reply = toupper(reply);
	while (reply != 'Y' && reply != 'N')
	{
		cout << " Error:" << endl;
		cout << " Please Enter Y or N";
		cin >> reply;
		reply = toupper(reply);
	}
	if (reply == 'Y')
	{
		cout << " Does a file need to be built?  " << endl;
		cin >> reply;
		reply = toupper(reply);
		while (reply != 'Y' && reply != 'N')
		{
			cout << " Error:" << endl;
			cout << " Please Enter Y or N";
			cin >> reply;
			reply = toupper(reply);
		}
		if (reply == 'Y')
		{
			

			build();
			
		}
		else
		{
			loadarray();
			search_data();
			
		}
		
			return 0;
		
	}
}
void build()
{

	fout.open("E:\\studentidarray.txt");
	while (reply == 'Y')
	{
		
		cout << " Please Enter your Student ID   ";
		cin >> studentid;
		cout << " Please Enter your Last Name   ";
		cin >> lastname;
		cout << " Please Enter your First Name    ";
		cin >> firstname;
		cout << " Please Enter Your GPA        ";
		cin >> gpa;


		while (gpa <= 0 || gpa >= 4)
		{
			cout << " Error ";
			cout << " Please enter a gpa between 0 - 4.0 ";
			cin >> gpa;
		}
		fout << studentid << " " << lastname << " " << firstname << " " << gpa << endl;
		cout << " Another Record? ";
		cin >> reply;
		reply = toupper(reply);
		while (reply != 'Y' && reply != 'N')
		{
			cout << " Error ";
			cout << " Please enter Y or N as a response ";
			cin >> reply;
			reply = toupper(reply);
		}
		if (reply == 'N')
		{
			loadarray();
			search_data();
		}
		
	}
		
		fout.close();
}

void loadarray() {
	fin.open("E:\\studentidarray.txt");
	
	string word;
	vector<string> myWords;
	while (fin >> word)
	{
		myWords.push_back(word);
		
	}
	fin.close();
	
}



void search_data()
{
	match = 'N';
    row = 0;
	maxsize = 8;

	cout << " enter a student id to be searched:    ";
	cin >> students;
									

	while (match == 'N' && row < maxsize)
	{
		if (students == studentid)
		{
			match = 'Y';
		}
		else
		{
			row = row + 1;
		}

		if (match == 'Y')
		{
			sucessful();
		}
		else
		{
			unsucessful();
		}
	}

			cout << " Another Search? ";
			cin >> moresearch;
			moresearch = toupper(moresearch);

	while (moresearch != 'Y' && moresearch != 'N')
		{
			cout << " Error ";
			cout << " Please enter Y or N as a response ";
			cin >> moresearch;
			moresearch = toupper(moresearch);
		}
	if (moresearch == 'Y')
		{
			search_data();
		}
}

void sucessful()
{
	cout << "student was found!" << endl << endl;
	if (gpa >= 3.65)
	{
		cout << firstname << " " << lastname << " " << "is on the Dean's List." << endl;
	}
	if(gpa >= 2.0 || gpa < 3.65)
	{
		cout << firstname << " " << lastname << " " << "is an average student." << endl;
	}
	if (gpa < 2.0)
	{
		cout << firstname << " " << lastname << " " << "is on Academic Probation." << endl;
	}


}
void unsucessful()
{
	cout << "Student ID was not found" << endl;
	;
}

Last edited by ekincaid2002; 03-20-2016 at 10:24 AM.
 
Old 03-20-2016, 09:45 AM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Your original search data function does not use the student array file. It only uses the values of the last entered student from your build function. Since Each student's data is a single string you need to parse it to separate the values.
 
Old 03-20-2016, 10:01 AM   #6
ekincaid2002
LQ Newbie
 
Registered: Mar 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
how do i do that and have all 4 elements still be linked as one entry? like i have to run a search on the id and the output that is displayed is based on the gpa of that student id. just realised i have 2 search data in here the one with match is the correct one im using.

Last edited by ekincaid2002; 03-20-2016 at 10:24 AM.
 
Old 03-20-2016, 10:39 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
There are many ways to split a string. Since we do not know what you have learned in class I'm not going to just provide you with an answer.
 
Old 03-20-2016, 10:50 AM   #8
ekincaid2002
LQ Newbie
 
Registered: Mar 2016
Posts: 12

Original Poster
Rep: Reputation: Disabled
array [] we have learned but i'm not good with that and don't really understand it well. should studentid be implemented like studentid[] ? and if i do it that way will the other elements still be able to be referenced by the id?
 
Old 03-20-2016, 07:46 PM   #9
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
No. What are you supposed to do with the vector myWords? Was that part of the assignment?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
serial search of text file ekincaid2002 Programming 8 03-18-2016 04:06 PM
Serious Serial port issues... ramesh6056 Linux - Hardware 4 01-15-2008 09:42 PM
USB Serial issues MGE Programming 4 12-13-2007 02:43 PM
Serial Port Issues corster Linux - Laptop and Netbook 1 04-08-2004 09:29 AM
Serial ATA device search on bootup taarnak Linux - General 0 11-25-2003 10:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration