+ 1
How can i do a Student regestration In C++ with Strings?
im new to this and I wish to know how i can do a Student regestration in C++. like The user types theyre name and second name, then Student number(they type a random number for practice numbers cuantity 6). and then email (random email for practice). Ontop of tht the numbers cant repeat from last digits like 130089/130080/130079. and When user types name it cant contain Numbers. How can i implement this example into the program?? please help me
21 Answers
+ 5
Here I have made part A like you told, I ran it on CPG no errors but you check if it meets your criteria by testing it on your laptop/pc.
I haven't tested it on laptop.
Now I leave part B of the code on you. Try to make it yourself, if you encounter any problem, ask it here
https://code.sololearn.com/cxjd2qf5uI5J/?ref=app
+ 6
Kinshuk Vasisht Yes you are correct, I forgot it and I also didn't ran it to check for errors. Thanks for mentioning.
Drowned Darkness The not so silent Gamer Queen Here is the working code without any errors
#include <iostream>
#include <string>
using namespace std;
struct data
{
string fname;
string lname;
int rollNum;
};
int main()
{
struct data students[2];
for(int i = 0; i < 2; i++)
{
cin >> students[i].fname;
cin >> students[i].lname;
cin >> students[i].rollNum;
}
for(int i = 0; i < 2; i++)
{
cout << students[i].fname << " ";
cout << students[i].lname << " ";
cout << students[i].rollNum << endl;
}
return 0;
}
+ 5
Can you elaborate what you trying to ask?
+ 5
welcome. happy to help
+ 3
Classes define a type, which is usable as other types like int, char, etc. Creating a Student array now is as easy as writing :
Student arr[50]; // 50 Students.
Also, note that if you try to print arr[49]'s number, you will automatically get 130049, which is the expected number for the 50th student.
+ 3
Here I have made a program for you to begin with. Now you proceed, if you get any problem ask about it.
#include <iostream>
#include <string>
using namespace std;
struct data
{
string fname;
string lname;
int rollNum;
}
int main()
{
data students[50];
for(int i = 0; i < 50; i++)
{
cin >> students.fname[i];
cin >> students.lname[i];
cin >> students.rollNum[i];
}
return 0;
}
+ 3
nAutAxH AhmAd There is an error in your code. students is an array, and it reduces to a pointer. So you cannot access students[0] without dereferencing it.
Also, fname[i] will read only a single character into the ith position of student 0 only, and rollNum is not an array, so you get an error when you try to access its value at index i.
So, the statements inside the loop should have been :
cin >> students[i].fname;
cin >> students[i].lname;
cin >> students[i].rollNum;
+ 2
WOOOW it worked on my pc *w*
Oh um question what if i use Cases to choose a specific option like
1) see regester list
2) add regester (adding how many want to add)
3) delete regester (specific to finder)
4)delete all regester
5) exit proggram
how will i be able to do that? i want to one up my bro as much as i can
+ 2
oh and what if the user accidently add a number in theyre name?
sorry for asking so many question im just Very interested and wish to know how to do some things with help....
+ 2
Drowned Darkness The not so silent Gamer Queen
Can you explain a bit more about what you mean by register list? Is it simply the list of all students that have been declared? For that, you need to declare a method that can print the student's data in a preferable format, and then call this function on all the students from the array.
Now, if your method was named print, then :
for(int i=0;i<n;i++)
{ arr[i].print(); }
Similarly, you can declare a read method.
As for the add and remove part, I suggest you use a vector of Student instead of a Student array, as then you can just push_back or erase the student into/from your vector. A vector also allows you to clear all its data in a single method call.
You can find details on vectors here : www.cplusplus.com/reference/vector/vector
Now, you can make your program menu driven to execute a particular set of operations as per user's choice. For that, use switch cases inside a while loop, and run the loop till the user exits.
+ 2
i had a fe trouble doing the second part But i managed and My bro is surprised Thank u all so much for helping me
+ 1
You can define a class named Student, which contains all required attributes as its members. You can then define methods to alter and access these members in different ways. As for the number count, to prevent repetition, declare a static member that can be incremented by one whenever you create an object (in the Constructors) and copy it to your student's number. You can also start the number count from 130000 that way.
So, the class looks something like :
class Student
{
std::string name;
std::string surname;
std::string email;
int number;
// static member to keep a
// count of numbers.
static int no_count;
public :
// Get the current count to your
// local Student object, and increment
// the main counter.
Student()
{ number=no_count++; }
};
// Start counting numbers from 130000.
int Student::no_count=130000;
For more details on classes, review the C++ lesson on Classes.
+ 1
i see... and if i wish to implement Arrays?
+ 1
Drowned Darkness The not so silent Gamer Queen
The class keyword is part of the syntax. It is mandatory.
As for the array, you need to declare it inside main, not in the class definition. If you keep this array here (which is declared in a wrong way though) it will be assumed that it is a member of the class Student.
So, in your code's main, declare the array like this:
int main()
{
// the int should not be used.
// as we need an array of
// Students.
Student arr[100];
// Other code follows...
// Execute some functions...
}
+ 1
Drowned Darkness The not so silent Gamer Queen I am sorry I wasn't able to provide a clear solution. I assumed you were familiar with basics of classes, which are already discussed in the SoloLearn's C++ course.
+ 1
im still in the process but i want to challenge my self against my bro. and he chsllenge me to a student regester and its so confusing
+ 1
And to check for a number, you will have to make a function that will compare each character and check if its ascii value is something other than one in the range of '0' and '9'.
Or you can use regex to match a particular format, which is in this case, only alphabets.
Include <regex> for this.
In the read method, call this :
regex_match(name,regex("[a-zA-Z]+");
This will return true or false, based on whether the name is valid or not (or the name is as per the format or not).
Then you can continue accordingly.
For more information, visit the following lessons :
https://www.sololearn.com/learn/261/?ref=app
https://www.sololearn.com/learn/9704/?ref=app
0
so it would be like
#include <iostream>
#include <string>
using namespace std;
int main ()
/*class Student*/
{
string name;
string surname;
string email;
int number;
int Student arr[100];
Student()
{ number=no_count++; }
};
int Student no_count=130000;
System ("pause")
0
im dealing with wizards here ugh... im just to confuse... but thank you for this help
0
ok ill explain in 2 parts
A
make like an archive regestry for Students in following steps
• add Full name (max of 100 students)
•students number
•email of student
1) the name of syudent cant contain numbers
2) when addjng student number it must start with 130-. it cant repeat numbers and it is needed to be atleast 6 digits long(130 included) and the proggram checks if it has the same Repeated Number for example (130-445, 130-444, 130-445*)once its a number repeated it has to say "same number please choose another"
3) when is asking for email it will ask like write the Start of ure email bc ut will automatically type (@progunion.col)
B
1)the program needs to save information in an external file for access it when proggram re open
2)add a metjod of Finding with option of Find by number or name. when choosen the info has to appear.
3)a method of ereasing all data or choosing file.
4) a exit
i hope this will give u the idea im trying to work on...