User Information Management With Unique Entry Check System

in #techclub27 days ago
Hello Everyone
I'm AhsanSharif From Pakistan
Greetings to you all, hope you all are well and enjoying a happy moment of life with steem. I'm also good Alhamdulillah.


image.png
Canva Design

User Data Collection System

Today I have brought you a mini project of C++ through which we can collect data from the user and collect it in a separate sheet. For this, we will have two files. One of them will be our data collection file, whose extension will be C++. In this file, we will write all our data and the other will be our file with the extension text UserData.txt where all our data will be stored.

An overview of our project is as follows: first we will have the user enter data and that data will be saved in a separate file. When the data is saved, our screen will be cleared and we will be shown a message that your data has been submitted. If our data has been submitted, if we want to add more data, we will continue by writing Y. If we want to end it, we will end it by writing N. If we write N, we will be shown a message that your work has been finished and the data has been submitted. If we write Y, then we will be asked to enter more data. The screen will be cleared once again and there we will take input from the user and the data will be submitted again in the same way.

If we have already entered data, then if we want to enter that data again, it will not be entered. We will receive a message that your data has already been submitted. Similarly, a user can submit his data only once.

DataCollection.cpp Explanation

First, we look at the explanation of the data collection file to see how the functions in our code are working and what their function is. The explanation is listed below.

Libraries:

First, let's talk about these libraries and why they are used.


image.png

  • #include <iostream>: The first one is that it supports our input and output operations, which include cin and cout.
  • #include <fstream>: This handles our file reading and writing operations.
  • #include <string>: This enables working with strings.
  • #include <cstdlib>: It is used for system commands such as clearing the screen, etc.
  • #include <set>: It is used to store data and check whether the data is unique or not.

Store User Data:


image.png

We have used a structure to hold all the information of the users, it holds the user's name, age, and email.

Track Submitted Users:


image.png

This saves the data of those who have already submitted and prevents them from submitting again if someone wants to.

Get Current User Count:


image.png

It opens the user data file and reads it line by line. If it sees a user written anywhere, then it will add the next user. Thus, if three users already exist, it will add the fourth user. This increases the user's count.

Collect & Save Data:


image.png

This declares the user object from the user data structure. It opens the file containing the user data and confirms that it adds the new data without deleting the previous data. This uses the getCurrentUserNumber() to call the next number.

Get User Input:


image.png

This function receives the user name as input and then checks using the submittedUsers.find(user.name) whether the data already exists or not. If it does, it prints a message that the data is already submitted.


image.png

Takes age and email as input and to remove the newline character left in the input buffer use cin.ignore().

Save Data:


image.png

This function writes the data to the data user file and sets the format in it. If there is a first user, then he will come first. If there is a user after that, then he will come in number two and if there is any after that, then he will come in number three. In this way, if the data is duplicated, then it is put in the submittedUser and ends it. If that file is not opening, then it will show a message that there was an error opening the file.

Screen Clearing & Show Confirmation:


image.png

Using system(slc) clears the screen and shows a success message if data has been successfully submitted.

Main Function:


image.png

This main function continues the user data collection until the user writes n. If the user writes y, then it adds more data and if the user writes n, then it shows the finished message. This input is obtained using do-while loops. It collects data using collectUserData(). Apart from this, after each entry, it clears the screen and either displays a finished message or adds new data.

Different Output

These are all the outputs that we get after doing this project. First, we are asked to enter the data. Secondly, when the data is entered, a message is shown. If you want to end this program, you will be shown a separate message. If you want to enter more data, you will be asked to continue. If the data has already been submitted, you will be shown that the data cannot be resubmitted.

Data Input
After Adding data
After Add data When We Finish
When User Adds Twice Same Data

user_data.txt Explanation

All the data that will be input by the user will be saved in a separate file. That file is shown below. Here all the data that has been submitted by different users is being shown. No data is duplicated because here data will be submitted only once.


image.png
Saved Data

Video Output

A video explanation of my entire project is given below, showing how the project works.

Cpp Code

The entire code of my project, using which I created this project, is given below.

image.png

Thank you so much for staying here. I hope you guys like my project. I would like to invite @kouba01, @karianaporras, @suboohi, and @abdullahw2 to join this club.

Cc:
@kafio @mohammadfaisal @alejos7ven

Dated: 06-03-2025 About Me

Sort:  
Loading...

muy bien, nunca había visto con la manera de gar algún tipo de base de datos a C++, a través de tu publicación pude profundizar un poco más en este lenguaje. Para la próxima publicación de este tema me gustaría ver alguna manera de leer esos datos previamente existentes en el archivo por ejemplo un buscador de usuarios. Buena suerte creándolo.

¿ Sabes si hay alguna manera de integrar alguna base de datos como My SQL en este lenguaje, de ser así me gustaría saber cómo?

buen trabajo

Thank you so much for the valuable feedback

For the next post on this topic I would like to see a way to read those data previously existing in the file, for example a user search engine.

We can create such a database using C++ where we can save all the user data. Absolutely, I will work on your suggestions. In the next post, I will definitely bring this feature that how the data we have from another file can be searched.

Do you know if there is a way to integrate a database like My SQL into this language?

Of course, we can integrate C++ with MySQL. The way to integrate it would be that we have to use the MySQL Connector C++ library. Through this library, we can perform our database operations. It allows us to insert update or delete records directly in the database in MySQL. You can download MySQL Connector C++ from the official MySQL website. Procedure:

For this, we have to install MySQL and MySQL Connector C++.
We have to include MySQL header files appropriately in our C++ code.
Using this mysql::connection object we have to connect to the MYSQL database.
Then using C++ run different queries like SELECT, UPDATE etc.

Cool, you can make a tutorial about using mysql with c++

Upvoted! Thank you for supporting witness @jswit.

Your project in C++ for user data collection is well-structure and efficiently handle input, storage, and duplication check. The use of all structures, file handling, and set for uniqueness ensure smooth functionality. The explanation is cleared, making this easy to understand that how the program operate.

If you add the feature to allow users to view all store data before enter the new information is the good approach. You can also implement data validation, such check email format, to improve the accuracy. use a graphical interface in the future can enhance user experience. Keep up the amazig work, and my best wishes for your programming journey!

Thank you very much for your good feedback. I am trying my best to improve my projects as much as possible so that it is easier for users to understand and perform.

Apart from this, I will make more changes in this project in the future, as our professor has also said, if a feature is added through which the user can see the previously added data, then I will add it in the next post, God willing. As you said, if validation is added, it will definitely be completed. Apart from that, we can see the data that is already available and that is already saved in another file.

I love programming, so I bring such a project to you. I am very happy that you liked my project. I will keep you updated with more such projects.