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 10740 gpraghuram 1,275
Recognized Expert Top Contributor
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,1234 5,&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 is written ( commented
out in code) then it reads in OK. However, when I move the code to the
right place ( as shown here) it throws an IO exception. Both the Filter
class and it's constituent class implement Serializable and it would seem
the...
|
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 = tmpfile();
/* write into 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 array). I cannot
change anything in the program but can add some features by which I
can convert this array of data into a file. The easiest thing would be
to write the data into a file (in hard disk) and use it. But I will be
working on thousands...
|
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 the end of
this message is the inflate method this is where I get stuck I know
that I need a byte array but because I am decompressing a string I
have no idea of how big the byte array will need to be in the end (the
inflate and deflate methods...
|
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 information from the text file!
Can anyone enlighten me as to what I am doing wrong?
| |
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 different image files shuffled up in one big binary file.
In order to view them I have to "unshuffle" the data, which means
moving bytes around. Currently my approach is to read the data from the
original, unshuffle as necessary, and then write...
|
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 have it store info it gets
from when the programs check in into a DataSet (XML file). Problem is, that
file now has to be used by other programs to find out version information
(the file is ALWAYS less that 1K.) The record itself is only five fields...
|
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 if I am wrong.
If possible could anybody help me with sample code for reading and writing a simple text file.I have seen there are many ways to read /write the data in Python.But I want to use the effective way of reading or writing the data...
|
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 00000000_00 0 000 000 000 0000 000
I need to read the file line by line and eventually parse out each
piece of the file and store in arrays that correspond to the specific
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |