I'm a beginner in C++. I'm in the process of writing an 'Automated Library Management System' using C++ on a Windows machine. I'm stuck in the midst of reading/writing data from a .csv file that holds the information about materials available in the library.
Any help is greatly appreciated!
2 10723
I'm a beginner in C++. I'm in the process of writing an 'Automated Library Management System' using C++ on a Windows machine. I'm stuck in the midst of reading/writing data from a .csv file that holds the information about materials available in the library.
Any help is greatly appreciated!
HI,
Till which point u have reached.?
And whats the area u are getting stuck?
Give more details so that people in the forum here can help u.
Raghuram
HI,
Till which point u have reached.?
And whats the area u are getting stuck?
Give more details so that people in the forum here can help u.
Raghuram
I have rest of the prog working...but the reading/writing from .csv is still not up. I was writing the function separately.
Here's what I have till now: -
#include <iostream>
-
#include <fstream>
-
using namespace std;
-
-
int main()
-
{
-
ifstream infile("test.csv");
-
char c[100];
-
int counter=0;
-
while (infile >> c[counter])
-
{
-
counter++;
-
}
-
-
cout << c << endl;
-
system("PAUSE");
-
return 0;
-
}
-
The output comes like:
John,Smith,12345,&James,Robert,67890,&
Now there's two things to be done:
1. Change "," to " " and "&" to newline using a loop.
2. Search each candidate using their id no.
How can these be done?
Is there any better method than an array of char?
_______________________________________
I'm also attaching the rest of the program that have so far (in case you need it answer my question). -
//ALMS Source code (Automated Library Management System) Version 1.0.0
-
//Built using Dev C++ (version 5) with Mingw compiler on Windows Platform
-
#include <iostream>
-
#include <sstream>
-
#include <string.h>
-
#include <windows.h>
-
#include <fstream>
-
#include <ctime>
-
#include <cstdlib>
-
using namespace std;
-
-
//////Accessory fucntion to set colors///////////////////////
-
void color(int i)
-
-
{ int a=0;
-
-
if (i==0)//password (black text-black background)
-
{a=0;}
-
if (i==1)//normal (white text-black background)
-
{a=15;}
-
if (i==2)//error (red text-black background)
-
{a=12;}
-
if (i==3)//header (white text-maroon background)
-
{a=79;}
-
-
HANDLE handle = GetStdHandle( STD_OUTPUT_HANDLE ); // Make a handle
-
SetConsoleTextAttribute( handle, a ); // Set the color of the text
-
}
-
//////////////Struct for ALMS//////////////////////
-
struct library
-
{
-
int isbn;
-
string subject, author;
-
}text, video, reference;
-
-
////////////////Quick Sort with Operator Overloading/////////////////
-
/*
-
template <class T>
-
int partition(T data[], int size)
-
{
-
T pivot = data[0];
-
int lo = 1;
-
int hi = size;
-
while (lo < hi) {
-
hi--;
-
while (data[lo] < pivot && lo < hi)
-
lo++;
-
while (data[hi] > pivot && lo < hi)
-
hi--;
-
if (lo < hi)
-
swap(data[lo], data[hi]);
-
}
-
if (lo > 0) {
-
if (data[lo] > pivot) lo--;
-
swap(data[lo],data[0]);
-
}
-
return(lo);
-
}
-
-
template <class T>
-
void quicksort(T data[], int size)
-
{
-
if (size > 1) {
-
int pivotloc = partition(data, size);
-
quicksort(data, pivotloc);
-
quicksort(data + pivotloc+1, size - pivotloc-1);
-
}
-
}
-
*/
-
///////////////////
-
-
////////About ALMS////////////////////////
-
void about_ALMS (void)
-
{
-
cout << "About ALMS:\n"
-
"ALMS (Automatic Library Maintainence System) is a freeware designed \nto aid libraries manage their material. "
-
"It is distributed under the \nCreative Commons License(BY-NC-ND). More details can be found at \nhttp://creativecommons.org/licenses/by-nc-nd/3.0/us/. "
-
"\nALMS is coded in C++ and compiled using Mingw compiler. ALMS has \nnot been tested on a wide range on machines. "
-
"Since it is a freeware, it is \ndistributed without any guarantee or liabilities.\n\n";
-
}
-
////////////Help topics about ALMS///////
-
void help_ALMS (void)
-
{
-
cout << "The Help section is still under construction\n";
-
}
-
///////////////Random Id-number generator//////////////////
-
int idgen(void)
-
{
-
srand((unsigned)time(0));
-
int random_integer;
-
int lowest=1000000000, highest=1999999999;
-
int range=(highest-lowest)+1;
-
for (int i=0; i<20; i++)
-
{
-
random_integer = lowest+int(range*rand()/(RAND_MAX + 1.0)) + rand()%23;
-
if (random_integer<0)
-
{
-
random_integer = random_integer*-1;
-
}
-
}
-
return random_integer;
-
-
}
-
-
////////////Logs user to their respective user accounts//////////////
-
int account (int i)
-
{
-
string s1, s2, input, greet="\nWhat would you like to do: \n(1) Login to your account \n(2) Register if you're a new user.\n";
-
string last, first, address, email;
-
int id;
-
if (i == 5)//Login to
-
{
-
s1 = "1";
-
-
}
-
else if (i == 6)//edit info again
-
{
-
s1 = "2";
-
}
-
else //fresh user from another function
-
{
-
cout << greet;
-
cin >> s1;//temporary string to hold user entry
-
}
-
if (s1.compare("1") == 0)
-
{
-
cout << "Please enter your ALMS user id: ";
-
cin >> input; //Numbers put in string to eliminate program crashing in the case user types non-integer values
-
cout << input;
-
-
//more things to come
-
}
-
else if (s1.compare("2") == 0)
-
{
-
id = idgen();
-
cout << "\nPlease fill the following fields:\n";
-
cout << "Name (Lastname Firstname): ";
-
cin >> last >> first;
-
cout << "Email: ";
-
cin >> email;
-
cout << "Account id: " << id <<". \nYou'll need this account id to log into your ALMS account later. \nDO NOT share this number with anyone else.\n ";
-
cout << "\nPlease review the information above before submittion:\n";
-
cout << "(1) Submit information \n(2) Change account information\n ";
-
cin >> s2;
-
if (s2.compare ("1") == 0)
-
{
-
account(5);
-
}
-
else if (s2.compare ("2") == 0)
-
{
-
account (6);
-
}
-
else {}//automatically goes back to welcome screen
-
}
-
return 0;
-
-
-
}
-
///////////distributes the task to different functions///////////////////
-
void task (int i)//i passed from pass
-
{
-
string s1,s3;//temporary string variables
-
string t[8] = {"\nWhat would you like to do: ", "Log into your account", "View help files", "Learn about ALMS", "Start over", "Modify/Add/Delete library material", "Search for user", "Retrieve user id"};
-
int j=0, count=0;//temporary variable used to store y/n value
-
s1.clear(); s3.clear();
-
-
if (i == 1 || i==2)//for students and faculty
-
{
-
cout << t[0] << endl;
-
for (int n=1; n<5; n++)
-
{
-
count++;
-
cout <<"("<<count<<")"<<" "<<t[n]<< endl;
-
}
-
cin >>s1;
-
if (s1.compare("1") == 0)//Log into account
-
{
-
account(i);
-
cout << endl;
-
task(1);
-
}
-
else if (s1.compare("2") == 0)//HELP!!
-
{
-
cout << "\n\n";
-
help_ALMS();
-
task (1);
-
}
-
else if (s1.compare("3") == 0)//About ALMS
-
{
-
cout << "\n\n";
-
about_ALMS();
-
task (1);
-
}
-
else if (s1.compare("4") == 0)//Start over
-
{
-
s1.clear();
-
}
-
-
}
-
-
else if (i == 3)//staff
-
{
-
-
cout << t[0] << endl;
-
for (int n=5; n<8; n++)
-
{
-
count++;
-
cout <<"("<<count<<")"<<" "<<t[n]<< endl;
-
}
-
cin>>s3;
-
if (s3.compare("1") == 0)//Modify Add/Delete Library material
-
{}
-
else if (s3.compare("2") == 0)//Search for user
-
{ }
-
else if (s3.compare("3") == 0)//Retrieve user id
-
{ }
-
else {cout << "Invalid Entry. Please try again:\n"; task(i);}
-
}
-
-
}
-
/////////////Password Function///////ONLY STAFF HAS TO GO THROUGH pass()/////////
-
void pass (int i)
-
{
-
if (i==1)
-
{task(1);}//student has no password check
-
-
else if (i==2)
-
{task (2);}//faculty has no password check either
-
-
else if (i == 3)
-
{
-
string passw, staff_pass="123", pass_error="Invalid staff password. ";
-
passw.clear();
-
cout << "Please enter staff password: ";
-
color(0);
-
cin >> passw;
-
color(1);
-
if (passw.compare(staff_pass) == 0)
-
{
-
task(3);
-
}
-
else
-
{
-
string temp;//used to store y/n data
-
color (2);
-
cout << pass_error;
-
color (1);
-
cout << "Try again? (1) Yes (2)No\t";
-
cin >> temp;
-
if (temp.compare("1") == 0 || temp.compare("yes") == 0 || temp.compare("Yes") == 0)
-
{
-
pass(3);
-
}
-
else {}//goes automatically back to main and continues from next statement
-
}
-
}
-
}
-
-
////////////Identifies the type of user accessing////////////////////
-
void userid (string u)
-
{
-
string s, greet="Welcome";//s is temporary storage for try again input
-
s.clear();//clears the entry string during each run of userid
-
string names[6] = {"student", "Student", "faculty", "Faculty", "staff", "Staff"}; //There are two of each to make it case-insensitive
-
-
if (u.compare( names[0] ) == 0 || u.compare( names[1] ) == 0)
-
{
-
cout << endl << greet << " " << names[1] << endl;
-
pass (1);
-
}
-
else if (u.compare( names[2]) == 0 || u.compare( names[3] ) == 0)
-
{
-
cout << endl << greet << " " << names[3] << endl;
-
pass (2);
-
}
-
else if (u.compare( names[4] ) == 0 || u.compare( names[5] ) == 0)
-
{
-
cout << endl << greet << " " << names[5] << endl;
-
pass (3);
-
}
-
else
-
{
-
color(2);
-
cout << "\nInvalid Entry. ";
-
color(1);
-
cout << "Try again? (1)Yes|(2)No\ ";
-
cin >> s;
-
if (s.compare("1") == 0)
-
{
-
s.clear();
-
cout << "\n\n";/*do noting and main automatically calls itself*/
-
}
-
else
-
{
-
s.clear();
-
u.clear();
-
cout << "\n";
-
}
-
-
}
-
}
-
////////////Main///////////////////////
-
int main (void)
-
{
-
color(3);//changes to header colors
-
string user, ALMS="ALMS (Automated Library Management System) [Version 1.0.0 ]";
-
cout << ALMS << endl; //Header file
-
color(1);//changes to default colors
-
cout << endl << "Please Login as: student | faculty | staff\t"; //Type of user
-
cin >> user;
-
userid (user); //calls func userid() to identify the type of user
-
cout << "\n\n";
-
main ();//recursive main to enable continuous usability of ALMS
-
return 0;
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Andy |
last post by:
Hi,
In the code below (not pretty I know but it's an early version :-P) I'm
having problems reading the data object back in. If I move the reading
code to immediately after the section where it...
|
by: Oliver Knoll |
last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode
(that is just writing, right?). How would one reopen it for reading?
I got the following (which works):
FILE *tmpFile =...
|
by: Jeevan |
last post by:
Hi,
I have an array of data (which I am getting from a socket connection).
I am working on a program which acts on this data but the program is
written to work on data from a file (not from an...
|
by: Nick |
last post by:
I have found a class that compresses and uncompresses data but need
some help with how to use part of it below is the deflate method which
compresses the string that I pass in, this works OK. At...
|
by: Alex Buell |
last post by:
I have a small text file which consist of the following data:
]]
And the code I've written is as follows:
]]
The trouble is, I can't work out why it goes into an infinite loop
reading the...
|
by: smeenehan |
last post by:
This is a bit of a peculiar problem. First off, this relates to Python
Challenge #12, so if you are attempting those and have yet to finish
#12, as there are potential spoilers here.
I have five...
|
by: UJ |
last post by:
I have a system that has five programs that all communicate with each other
via Message Queues. Works well. One program is a watchdog that will make
sure the others are up and going. Currently I...
|
by: arne.muller |
last post by:
Hello,
I've come across some problems reading strucutres from binary files.
Basically I've some strutures
typedef struct {
int i;
double x;
int n;
double *mz;
|
by: psbasha |
last post by:
Hi,
Is it necessary in Python to close the File after reading or writing the data to file?.While refering to Python material ,I saw some where mentioning that no need to close the file.Correct me...
|
by: Stephen.Schoenberger |
last post by:
Hello,
My C is a bit rusty (.NET programmer normally but need to do this in
C) and I need to read in a text file that is setup as a table. The
general form of the file is
00000000 USNIST00Z...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |