Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 25th, 2008, 9:01 PM   #1
verizondude
Newbie
 
verizondude's Avatar
 
Join Date: Mar 2008
Posts: 4
Rep Power: 0 verizondude is on a distinguished road
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;
		
		}
Thank You for helping us with our problems!!!
verizondude is offline   Reply With Quote
Old Mar 25th, 2008, 10:07 PM   #2
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 647
Rep Power: 4 OpenLoop is on a distinguished road
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)
  1. #include <string>
  2.  
  3. ...
  4. string username;
  5. cin>>username;
  6. cout>>username;
  7. ...
OpenLoop is offline   Reply With Quote
Old Mar 26th, 2008, 6:26 AM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,435
Rep Power: 8 Ooble is on a distinguished road
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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 26th, 2008, 9:52 AM   #4
verizondude
Newbie
 
verizondude's Avatar
 
Join Date: Mar 2008
Posts: 4
Rep Power: 0 verizondude is on a distinguished road
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.
verizondude is offline   Reply With Quote
Old Mar 26th, 2008, 7:46 PM   #5
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 864
Rep Power: 3 lectricpharaoh is on a distinguished road
Re: I kind of need help on my program

Quote:
Originally Posted by verizondude
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.
Ahh. what you want, then, is a collection of structs. The simplest is an array or vector. As you seem to have already covered arrays, just use one of those. A vector is a type from the standard template library that is an abstraction of an array; it provides very similar functionality, with some added perks such as range-checking and the ability to be resized.
__________________
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
lectricpharaoh is offline   Reply With Quote
Old Mar 27th, 2008, 8:07 AM   #6
Soulstorm
Hobbyist Programmer
 
Soulstorm's Avatar
 
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 231
Rep Power: 3 Soulstorm is on a distinguished road
Re: I kind of need help on my program

Quote:
Originally Posted by verizondude View Post
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.
Hm... Maybe I didn't understand well, but you have encountered a problem where different students have a different set of attributes, and so you may need a specific struct to define each one?

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)
Soulstorm is offline   Reply With Quote
Old Mar 31st, 2008, 7:00 PM   #7
verizondude
Newbie
 
verizondude's Avatar
 
Join Date: Mar 2008
Posts: 4
Rep Power: 0 verizondude is on a distinguished road
Re: I kind of need help on my program

Quote:
Originally Posted by lectricpharaoh View Post
Ahh. what you want, then, is a collection of structs. The simplest is an array or vector. As you seem to have already covered arrays, just use one of those. A vector is a type from the standard template library that is an abstraction of an array; it provides very similar functionality, with some added perks such as range-checking and the ability to be resized.
Well seeing a vector as like being a massive array, wouldn't the user have to count the characters he/she would want to plug in?
verizondude is offline   Reply With Quote
Old Apr 1st, 2008, 3:14 PM   #8
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 864
Rep Power: 3 lectricpharaoh is on a distinguished road
Re: I kind of need help on my program

Quote:
Originally Posted by verizondude
Well seeing a vector as like being a massive array, wouldn't the user have to count the characters he/she would want to plug in?
For any data type that is a collection of elements, space needs to be allocated for the elements.

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)
  1. struct g_Personalinfo
  2. {
  3. char firstname[10];
  4. char lastname[15];
  5. int age;
  6. char school[30];
  7. char subject[30];
  8. int grade;
  9. };
This does not actually create an instance. Rather, it only tells compiler what the type is composed of, so you can use it. I'm sure you already know this part. You need to create one or more instances, but you can create them either one at a time, or a bunch at once in an array:
C++ Syntax (Toggle Plain Text)
  1. g_Personalinfo singleItem;
  2. g_Personalinfo arrayOfItems[100]; // room for 100 elements
If you use the array, you have to provide a subscript, just like with any other array access:
C++ Syntax (Toggle Plain Text)
  1. arrayOfItems[7].age = 19;
Now, this all works dandy until you exceed 100 students, or whatever type your array holds. It also means if you use less, you're wasting space. A vector is a better solution here. The syntax looks a bit funny, because vector is actually a template; think of a template as a layout, with an actual type filled in at runtime. It will look something like this:
C++ Syntax (Toggle Plain Text)
  1. // remember to #include <vector>
  2. vector<g_Personalinfo> vectorOfItems(100); // 100 elements
You can then use it with array-style subscript notation, and you can 'push' elements on the end of the vector, or 'insert' them in the middle. If the vector is full when you add an element, it will resize itself. Thus, you don't need to worry so much about the size. There are methods for controlling how much space it reserves, and how it resizes itself, if you're paranoid it'll reserve too much (wasting space) or too little (meaning resizing happens more often, and resizing tends to be a slow operation).

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
lectricpharaoh is offline   Reply With Quote
Old Apr 24th, 2008, 9:41 AM   #9
verizondude
Newbie
 
verizondude's Avatar
 
Join Date: Mar 2008
Posts: 4
Rep Power: 0 verizondude is on a distinguished road
Re: I kind of need help on my program

Ok I got the idea, thanks lectripharaoh
verizondude is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:25 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC