![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2008
Posts: 4
Rep Power: 0
![]() |
I kind of need help on my program
Hi,
My partner and me are kind of new to c++ and we're working on a program that is rather hard(for our capabilities on c++). Our program is nearly finished and all we have to do is to allow our program to accept some data. The problem is that we want the user to be able to name his/her own structs as it will store their personal data/ students' data, but we don't know how . We also want the program to store the user defined names of the structs within another one that would allow data storage for each one of those names. The closest thing we could actually get to solving my problem was a block of code that asked for number of names and names and stored them in a char array(which didn't really work as the user would then actually have to count all the letters of the names that he/her would want to put in Anyway, here's the code if you want to look at it: // Cesis2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
char g_NewUser[15];
char g_NewPassword1[20];
int g_x=0;
int g_hi=0;
int g_show=0;
int g_y=0;
struct g_Personalinfo
{
char firstname[10];
char lastname[15];
int age;
char school[30];
char subject[30];
int grade;
};
struct g_student
{
char firstname[10];
char lastname[15];
int age;
char school[30];
int grade;
};
int main()
{
using namespace std;
g_Personalinfo name;
menu:
cout<<"Welcome to Cesis!!!"<<endl;
cout<<"What Will You Like To Do?"<<endl;
cout<<"1)Login"<<endl;
cout<<"2)New User"<<endl;
cout<<"3)Exit"<<endl;
int menu;
cin>>menu;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
switch (menu)
{
case 1:
cout<<"Username:"<<endl;
char username[15];
cin>>username;
cout<<"Password:"<<endl;
char password[20];
cin>>password;
g_x=0;
g_show=1;
g_hi=1;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
goto accountinfo;
break;
case 2:
cout<<"Username:"<<endl;
cin>>g_NewUser;
cout<<"Password:"<<endl;
cin>>g_NewPassword1;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
goto newuser;
break;
case 3:
cin.get();
break;
default:
cout<<"Error Error!!! \a \a"<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
goto menu;
break;
}
newuser:
int newuser1;
g_x=1;
cout<< "Username and Password Comfirmed"<<endl;
cout<< "Choose Where To Go"<<endl;
cout<< "1) Put Account In FO SHO"<< endl;
cout<< "2} Loga Outa (that meens log out in gansta talk)"<< endl;
cin>> newuser1;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
switch (newuser1)
{
case 1:
cout<<"Going to Account In FO SHO"<< endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
goto accountinfo;
break;
case 2:
goto menu;
break;
default:
goto menu;
break;
}
personalinfochange2:
int la;
int a=0;
int b=0;
int c=0;
int d=0;
int e=0;
int f=0;
if (g_y==0)
{
int w;
cout<<"Please Type In Your First Name:";
cin>>name.firstname;
cout<<"Please Type In Your Last Name:";
cin>>name.lastname;
cout<<"Please Type In Your Age:";
cin>>name.age;
cout<<"Please Type In Your School's Name:";
cin>>name.school;
cout<<"Please Type In Your Profession's Subject (If You Have More Then One Then One Subject, Type A Comma After Each One:";
cin>>name.subject;
cout<<"Please Type In Your Profession's Grade Level:";
cin>>name.grade;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
g_y=1;
goto switchy;
}
else
{
cout<<"What Information Would You Like To Change?"<<endl;
cout<<"1. First Name:"<<name.firstname<<endl;
cout<<"2. Last Name:"<<name.lastname<<endl;
cout<<"3. Age:"<<name.age<<endl;
cout<<"4. School:"<<name.school<<endl;
cout<<"5. Profession's Subject(s):"<<name.subject<<endl;
cout<<"6. Profession's Grade Level:"<<name.grade<<endl;
cin>>la;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<""<<endl;
switch(la)
{
case 1:
cout<<"Changeing Information to:";
cin>>name.firstname;
cout<<"Is This the Correct Information?"<<endl;
cout<<"First Name:"<<name.firstname<<endl;
cout<<"1)Yes Or 2)No?"<<endl;
cin>>a;
switch(a)
{
case 1:
cout<<"Thank You... Returning Back to Acount Info"<<endl;
goto accountinfo;
break;
case 2:
cout<<"Please Retry Again..."<<endl;
cout<<"Going Back To Account Info Change Menu"<<endl;
goto personalinfochange2;
break;
default:
cout<<"Error Error! \a \a "<<endl;
goto personalinfochange2;
break;
}
break;
case 2:
cout<<"Changeing Information to:";
cin>>name.lastname;
cout<<"Is This the Correct Information?"<<endl;
cout<<"Last Name:"<<name.lastname<<endl;
cout<<"1)Yes Or 2)No?"<<endl;
cin>>b;
switch(b)
{
case 1:
cout<<"Thank You... Returning Back to Acount Info"<<endl;
goto accountinfo;
break;
case 2:
cout<<"Please Retry Again..."<<endl;
cout<<"Going Back To Account Info Change Menu"<<endl;
goto personalinfochange2;
break;
default:
cout<<"Error Error! \a \a "<<endl;
goto personalinfochange2;
break;
}
break;
case 3:
cout<<"Changeing Information to:";
cin>>name.age;
cout<<"Is This the Correct Information?"<<endl;
cout<<"Age:"<<name.age<<endl;
cout<<"1)Yes Or 2)No?"<<endl;
cin>>c;
switch(c)
{
case 1:
cout<<"Thank You... Returning Back to Acount Info"<<endl;
goto accountinfo;
break;
case 2:
cout<<"Please Retry Again..."<<endl;
cout<<"Going Back To Account Info Change Menu"<<endl;
goto personalinfochange2;
break;
default:
cout<<"Error Error! \a \a "<<endl;
goto personalinfochange2;
break;
}
break;
case 4:
cout<<"Changeing Information to:";
cin>>name.school;
cout<<"Is This the Correct Information?"<<endl;
cout<<"School:"<<name.school<<endl;
cout<<"1)Yes Or 2)No?"<<endl;
cin>>d;
switch(d)
{
case 1:
cout<<"Thank You... Returning Back to Acount Info"<<endl;
goto accountinfo;
break;
case 2:
cout<<"Please Retry Again..."<<endl;
cout<<"Going Back To Account Info Change Menu"<<endl;
goto personalinfochange2;
break;
default:
cout<<"Error Error! \a \a "<<endl;
goto personalinfochange2;
break;
}
break;
case 5:
cout<<"Changeing Information to:";
cin>>name.subject;
cout<<"Is This the Correct Information?"<<endl;
cout<<"Profession's Subject:"<<name.subject<<endl;
cout<<"1)Yes Or 2)No?"<<endl;
cin>>e;
switch(e)
{
case 1:
cout<<"Thank You... Returning Back to Acount Info"<<endl;
goto accountinfo;
break;
case 2:
cout<<"Please Retry Again..."<<endl;
cout<<"Going Back To Account Info Change Menu"<<endl;
goto personalinfochange2;
break;
default:
cout<<"Error Error! \a \a "<<endl;
goto personalinfochange2;
break;
}
break;
case 6:
cout<<"Changeing Information to:";
cin>>name.grade;
cout<<"Is This the Correct Information?"<<endl;
cout<<"Profession's Grade:"<<name.grade<<endl;
cout<<"1)Yes Or 2)No?"<<endl;
cin>>f;
switch(f)
{
case 1:
cout<<"Thank You... Returning Back to Acount Info"<<endl;
goto accountinfo;
break;
case 2:
cout<<"Please Retry Again..."<<endl;
cout<<"Going Back To Account Info Change Menu"<<endl;
goto personalinfochange2;
break;
default:
cout<<"Error Error! \a \a "<<endl;
goto personalinfochange2;
break;
}
default:
cout<<"Error Error! \a \a "<<endl;
goto personalinfochange2;
break;
}
}
switchy:
int w;
cout<< "Here is the Info You Put In."<< endl << "First Name:" << name.firstname << endl << "Last Name:" << name.lastname << endl << "Age:" << name.age << endl << "School's Name:" << name.school << endl << "Subjects:" << name.subject << endl << "Grade:" << name.grade << endl;
cout<< "Is The Info Correct?"<<endl;
cout<< "1)Yes or 2)No"<<endl;
cin>>w;
switch(w)
{
case 1:
cout<<"Going Back to AccountInfo"<<endl;
g_hi=1;
g_show=1;
goto accountinfo;
break;
g_y=1;
case 2:
cout<<"Please Re-Type Everthing:"<<endl;
goto personalinfochange2;
break;
default:
cout<<"Error Error! \a \a "<<endl;
goto switchy;
break;
}
accountinfo:
if (g_x==1)
{
int y;
cout<<"Welcome New User! I would like to know more about you to increase our knowledge.";
cout<<"Please go to New Info and type in your info. We would appriciate it if you told us the right infomation about you."<<endl;
cout<<"What do you want to do?"<<endl;
cout<<"1.Put in new info"<<endl;
cout<<"2.Go to account menu"<<endl;
cout<<"3.Go to main menu"<<endl;
cout<<"4.Log out"<<endl;
cin>>y;
switch (y)
{
case 1:
g_x=0;
goto personalinfochange;
break;
case 2:
g_x=0;
goto accountinfo;
break;
case 3:
g_x=0;
goto menu;
break;
case 4:
cin.get();
g_x=0;
break;
default:
cout<<"Error Error! \a \a "<<endl;
goto accountinfo;
break;
}
}
else
{ goto show1;}
show1:
if(g_show==1)
{
int z;
cout<<""<<endl;
cout<<"Welcome Back... What do you want to do?"<<endl;
cout<<"1)Change Account Info"<<endl;
cout<<"2)Go To Student Info"<<endl;
cout<<"3)Show Information About Yourself"<<endl;
cout<<"4)Log Out"<<endl;
cin>>z;
switch (z)
{
case 1:
goto personalinfochange;
break;
case 2:
goto studentinfo;
break;
case 3:
goto switchy;
break;
case 4:
cout<<"Logging Out";
goto menu;
break;
default:
cout<<"Error Error! \a \a "<<endl;
goto accountinfo;
break;
}
}
else
{
int z;
cout<<"Welcome Back... What do you want to do?"<<endl;
cout<<"1)Change Account Info"<<endl;
cout<<"2)Go To Student Info"<<endl;
cout<<"3)Log Out"<<endl;
cin>>z;
switch (z)
{
case 1:
goto personalinfochange;
break;
case 2:
goto studentinfo;
break;
case 3:
cout<<"Logging Out";
goto menu;
break;
default:
cout<<"Error Error! \a \a "<<endl;
goto accountinfo;
break;
}
}
personalinfochange:
int ppedpdsa;
cout<<"Want to Change Your Personnal Info?"<<endl;
cout<<"Please type in 1(Yes) or 2(No)"<<endl;
cin>> ppedpdsa;
switch (ppedpdsa)
{
case 1:
goto personalinfochange2;
break;
case 2:
cout<<"Going Back To Account Menu"<<endl;
goto accountinfo;
break;
default:
cout<<"Error Error! \a \a "<<endl;
goto personalinfochange;
break;
}
studentinfo:
int LALALAL;
cout<<"Welcome To Your Students Information"<<endl;
cout<<"If You're New, We Recommend Making New Students, Then Making A New Class"<<endl;
cout<<""<<endl;
cout<<"What Will You Like to Do?"<<endl;
cout<<"1)View All Your Classes"<<endl;
cout<<"2)Make A New Class"<<endl;
cout<<"3)Make A New Student";
cin>>LALALAL;
switch (LALALAL)
{
case 1:
cout<<"Going To Classes"<<endl;
break;
case 2:
break;
case 3:
goto createnewstudent;
break;
default:
cout<<"Error Error! \a \a "<<endl;
goto studentinfo;
break;
}
createnewstudent:
cout<<"How many students do you have?"<<endl;
int number;
cin>>number;
while (number>0)
{
cout<<"Name?"<<endl;
number--;
}
system("pause");
return 0;
}![]() ![]() |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
Re: I kind of need help on my program
What do you mean with "name his/her own structs"? Are you saying you want the users to name the actual object of the struct??? Users shouldn't even know that you're using a struct, all they care about is that you save their information. You can declare an array of struct objects (100 for example) and then use them as needed. Or if you want to get fancy, look into Vector (dynamic) arrays.
On a side note, why not use the string class instead of all the char[] arrays: c++ Syntax (Toggle Plain Text)
|
|
|
|
|
|
#3 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 8
![]() |
Re: I kind of need help on my program
If you mean you want them to name each block of information (that you store in a struct) so they can find it later, you can use a map to do it:
struct blockOfInfo oldInfo, newInfo; std:map<string, struct blockOfInfo> info; info["name"] = oldInfo; newInfo = info["name"]; Cprogramming.com has a good tutorial on maps. |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Mar 2008
Posts: 4
Rep Power: 0
![]() |
Re: I kind of need help on my program
What we want to do is to make a struct that can be remade into diffrent type of that struct. Like you want to add a new student to your database. we use the student struct to get his information. we want it so that all the diffrent students have a diffrent struct so that we dont have manually add a new struct every time some is new. so its automated.
|
|
|
|
|
|
#5 | |
|
Caffeinated Neural Net
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 889
Rep Power: 4
![]() |
Re: I kind of need help on my program
Quote:
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp |
|
|
|
|
|
|
#6 | |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 233
Rep Power: 3
![]() |
Re: I kind of need help on my program
Quote:
Well, if that's the case you should also look into classes and inheritance. You will need to make a base class and then make subclasses to cover all your needs. You can then add any subclass of that base class into a vector or an array and process them.
__________________
Project::Soulstorm (personal homepage) |
|
|
|
|
|
|
#7 | |
|
Newbie
Join Date: Mar 2008
Posts: 4
Rep Power: 0
![]() |
Re: I kind of need help on my program
Quote:
|
|
|
|
|
|
|
#8 | |
|
Caffeinated Neural Net
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 889
Rep Power: 4
![]() |
Re: I kind of need help on my program
Quote:
As an example, imagine a C-style string (array of char, with the string's end marked by a zero). You need to allocate space for the string plus an additional char element for the zero terminator. However, there are data structures that hide this sort of thing from you. The C++ string class is a good example. It allocates a block behind the scenes- say 20 characters- and tracks the current length of the string. It then allocates a larger block if it needs to, but this is all hidden from the user of the class.A vector is similar. Say you have a struct defined like so: C++ Syntax (Toggle Plain Text)
C++ Syntax (Toggle Plain Text)
C++ Syntax (Toggle Plain Text)
C++ Syntax (Toggle Plain Text)
The upshot of all this is that the user will not need to know in advance how many items they're inputting. The vector is sized to a default or specified size, and if this turns out to be too small, it will grow as needed. Anyways, you can read all about vectors right here (this reference in general is quite helpful and to-the-point, I find).
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp |
|
|
|
|
|
|
#9 |
|
Newbie
Join Date: Mar 2008
Posts: 4
Rep Power: 0
![]() |
Re: I kind of need help on my program
Ok I got the idea, thanks lectripharaoh
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| hello, I'd like to write a program for my work. | blake_jl | Community Introductions | 13 | Nov 23rd, 2007 4:31 PM |
| Language display in program | Prm753 | C++ | 3 | May 30th, 2006 5:45 PM |
| Help me make a program. read ---> | DBZ | Visual Basic | 8 | Mar 10th, 2006 8:53 AM |
| Creating a program to test a program | sixstringartist | C | 8 | Jan 21st, 2006 1:15 PM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 4:12 PM |