GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #11  
Old 03-May-2005, 14:35
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough
Sorry 'bout that marita. I don't have problems using getline() that way. Does using the std:: in either way suggested solve the problem?

I compile with GNU gcc for cygwin and differences are very possible.

Mark
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
  #12  
Old 03-May-2005, 14:41
marita marita is offline
New Member
 
Join Date: Apr 2005
Posts: 25
marita is on a distinguished road
Its okay.
yeah, the std::getline fixed the problem, but still i cant get the code to work.
Here's the output:

PhoneBook

Last First Phone number
Juanita RivePepiPanchita Marie NievesJuanita RivePepiPanchita PepiPanc
hita-Panchita

PhoneBook

Last First Phone number
-

PhoneBook

Last First Phone number
-

PhoneBook

Last First Phone number
-

PhoneBook

Last First Phone number
-

Press any key to continue


IS there way that i can get the file to output correctly and make corrections to it as suggested.
I explain my self.
That if the user wants to edit the area code he can.
That if the user wants to edit the phone number he can.
That if the user wants to edit the entire thing (phonenumber, area code and name) he can?
  #13  
Old 03-May-2005, 14:45
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough
I would be willing to be your .txt file looks a lot different than mine. By using getline you are reading in the entire line in the file, and putting it in each variable in turn. Perhaps yours needs to look for spaces or something else. Could you post the phonebook.txt.

Mark
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
  #14  
Old 03-May-2005, 14:48
marita marita is offline
New Member
 
Join Date: Apr 2005
Posts: 25
marita is on a distinguished road
Here's the .txt:

code]Marie Nieves (555) 555-5555
Juanita Rivera (777) 777-7777
Pepito Conde (888) 888-8888
Panchita Cruz (999) 999-9999[/code]
  #15  
Old 03-May-2005, 15:18
marita marita is offline
New Member
 
Join Date: Apr 2005
Posts: 25
marita is on a distinguished road
do you need anything else?
  #16  
Old 03-May-2005, 15:24
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough
Quote:
Originally Posted by marita
do you need anything else?

Actually yes. I introduced using a string and getline without knowing if you can even use these for your project. Can you and are you familiar with using them? Also, do you have any suggestions on how to do this? I am reading in a complete line from your file and it will now have to be parsed for spaces and put the proper values in the proper place.

Anything else of value you may want to add will be helpful. The way I see it, there should be a member function that takes a string as an argument and cuts and pastes what it needs. This can be done with string manipulators if you are familiar with the <string> class.

You could also take a look at how I declare the PhoneNumber objects. It is not dynamic. Make some suggestions there.

Mark
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
  #17  
Old 03-May-2005, 16:58
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough
Ok, this is a really straight forward way to load your variables. I am assuming you can use getline and strings for this. Not fancy, the code could be reduced by about two thirds but since I don't know if you have a plan of attack this will have to serve for now.

The .txt file you had has 4 items per line, each ending in a space. That is a tip off right there. There is a function isspace(string) that can be called to check when you find it. Here is the general concept. You get your line from the file using getline.

input = "Marie Nieves (555) 555-5555 "

So now you want everything up to the first space (but not the space) to be placed in FirstName which is a character array. I increased the sizes of your arrays as some were too small and were being overrun. Always remember your total number of chars plus your termination make up the char string. Here is the beginning of the new member function.

CPP / C++ / C Code:
  void parse_words(string& temp){
    // Let's set the arrays to be empty
    int index =0;
    FirstName[0] = '\0';
    LastName[0] = '\0';
    AreaCode[0] = '\0';
    PhoneNumber[0] = '\0';
    // do FirstName
    while ( !isspace(temp[index])){
      FirstName[index] = temp[index];
      FirstName[index+1] = '\0';
      index++;
    };
    temp.erase(0,index+1);
    index = 0;
    // do LastName
    while ( !isspace(temp[index])){
      LastName[index] = temp[index];
    // removed code below here

First I set all the char arrays to be empty by placing a '\0' in the first position. Then the while loop copies the string passed (adding the terminator) until it finds a space. Then the passed string is cut, the index is reset and off to the races again and again and finally for the PhoneNumber. It is linear and boring but it works well. Since this code is repeated with the different variable names you may be better served by reducing the fuction to this and passing a cut version of the input string. Here is how I called it from main.

CPP / C++ / C Code:
  book.open("PhoneBook.txt", ios::in);
  if (!book){
    cout << "ERROR! opening phonebook.txt" << endl;
    return -1; // so we don't print junk
  }else {
      for (int i=0; i< 5; i++){
        getline(book, input);
        array[i].parse_words(input);
      }
  }

Well, digest that and come up with a plan for the rest. Hope this gets you on your way. If you have any question ask. Someone here will most likely be able to answer them.

Mark
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
  #18  
Old 04-May-2005, 13:07
marita marita is offline
New Member
 
Join Date: Apr 2005
Posts: 25
marita is on a distinguished road
CPP / C++ / C Code:
class PhoneBook
{
public:
	PhoneBook();


private:
	char name;
	char lastname;
	int areacode;
	int phone;
	
};




fp.open

for (i=0; i < /* quantity of objects in the file*/ ; i++)
f= a.getData(fp)
arreglo [i] = f;



//FUNCTION GETDATA

PhoneBook.getData()
{
	objeto a;

	fp >> a.name 
		return a;
}

int main()
{
	char option;
	int i=0;


//Menu
	do
	{  
		cout<<"           Menu           "<<endl;                      //print menu
		cout << "What would you like to do? " << endl;
		cout<<"(1) Change Area Code"<<endl;                  //print option (1) to change the Area Code
		cout<<"(2) Change Phone Number"<<endl;               //print option (2) to change the Phone Number
		cout<<"(3) Change Area Code & Phone Number"<<endl; //print option (3) to change Area Code & Phone Number
		cout<<"(4) Print"<<endl;              //print option (4) for printing
		cout<<"(5) Salir"<<endl;              //print option (5) to exit
	
		cin >> option;


			switch (option)                        // begins switch structure
		{
			case 1:  
				cout << "Enter the name and last name of the person you would like to edit: ";
				cin >> name >> last name;

				for (i=0; i < cant; i++)
				{
						for (int i =0; i<10; i++)
						data [i] = toupper (data[i]);

						if (strcmp (name, array [i].name)) && (strcmp (lastname, array [i].lastname))
						{
							array[i].()
						}
				}
				break;


			case 2:  
				cout << "Enter the name and last name of the person you would like to edit: ";
				cin >> name >> last name;

				for (i=0; i < cant; i++)
				{
						for (int i =0; i<10; i++)
						data [i] = toupper (data[i]);

						if (strcmp (name, array [i].name)) && (strcmp (lastname, array [i].lastname))
						{
							array[i].[]
						}
				}
				break;


				case 3:  
				cout << "Enter the name and last name of the person you would like to edit: ";
				cin >> name >> last name;

				for (i=0; i < cant; i++)
				{
						for (int i =0; i<10; i++)
						data [i] = toupper (data[i]);

						if (strcmp (name, array [i].name)) && (strcmp (lastname, array [i].lastname))
						{
							array[i].=
						}
				}
				break;


				case 4:  
					// Imprime el archivo

				break;


				case 5:  
					cout<<"Exiting...."<<endl;  //exits
			
				break;


				default:
				cout<<"Select and option from 1 -> 5"<< endl;
				break;
		}                                        //end swicth structure
	}while(operation !=5);    //end do/while structure

	/* Falta:
			- tengo que buscar donde esta el cursor
			- escribir en el archivo
			- darle delete a la memoria dinamica
			- cerrar el archivo
	*/

return 0;
}

         


the errors are:
c:\documents and settings\ee181\desktop\cpp1.cpp(26) : error C2143: syntax error : missing ';' before '.'
c:\documents and settings\ee181\desktop\cpp1.cpp(26) : error C2501: 'fp' : missing storage-class or type specifiers
c:\documents and settings\ee181\desktop\cpp1.cpp(26) : error C2143: syntax error : missing ';' before '.'
c:\documents and settings\ee181\desktop\cpp1.cpp(2 : error C2143: syntax error : missing ')' before ';'
c:\documents and settings\ee181\desktop\cpp1.cpp(2 : error C2143: syntax error : missing ';' before '<'
c:\documents and settings\ee181\desktop\cpp1.cpp(2 : error C2501: 'i' : missing storage-class or type specifiers
c:\documents and settings\ee181\desktop\cpp1.cpp(2 : error C2143: syntax error : missing ';' before '<'
c:\documents and settings\ee181\desktop\cpp1.cpp(2 : error C2143: syntax error : missing ';' before '++'
c:\documents and settings\ee181\desktop\cpp1.cpp(2 : error C2501: 'i' : missing storage-class or type specifiers
c:\documents and settings\ee181\desktop\cpp1.cpp(2 : error C2086: 'i' : redefinition
c:\documents and settings\ee181\desktop\cpp1.cpp(2 : error C2143: syntax error : missing ';' before '++'
c:\documents and settings\ee181\desktop\cpp1.cpp(2 : error C2059: syntax error : ')'
c:\documents and settings\ee181\desktop\cpp1.cpp(36) : error C2143: syntax error : missing ';' before '.'
c:\documents and settings\ee181\desktop\cpp1.cpp(36) : error C2143: syntax error : missing ';' before '.'
c:\documents and settings\ee181\desktop\cpp1.cpp(37) : error C2143: syntax error : missing ';' before '{'
c:\documents and settings\ee181\desktop\cpp1.cpp(37) : error C2447: missing function header (old-style formal list?)
c:\documents and settings\ee181\desktop\cpp1.cpp(54) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\ee181\desktop\cpp1.cpp(54) : error C2297: '<<' : illegal, right operand has type 'char [27]'
c:\documents and settings\ee181\desktop\cpp1.cpp(54) : error C2065: 'endl' : undeclared identifier
c:\documents and settings\ee181\desktop\cpp1.cpp(55) : error C2297: '<<' : illegal, right operand has type 'char [28]'
c:\documents and settings\ee181\desktop\cpp1.cpp(56) : error C2297: '<<' : illegal, right operand has type 'char [21]'
c:\documents and settings\ee181\desktop\cpp1.cpp(57) : error C2297: '<<' : illegal, right operand has type 'char [24]'
c:\documents and settings\ee181\desktop\cpp1.cpp(5 : error C2297: '<<' : illegal, right operand has type 'char [36]'
c:\documents and settings\ee181\desktop\cpp1.cpp(59) : error C2297: '<<' : illegal, right operand has type 'char [10]'
c:\documents and settings\ee181\desktop\cpp1.cpp(60) : error C2297: '<<' : illegal, right operand has type 'char [10]'
c:\documents and settings\ee181\desktop\cpp1.cpp(62) : error C2065: 'cin' : undeclared identifier
c:\documents and settings\ee181\desktop\cpp1.cpp(62) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
c:\documents and settings\ee181\desktop\cpp1.cpp(6 : error C2297: '<<' : illegal, right operand has type 'char [68]'
c:\documents and settings\ee181\desktop\cpp1.cpp(69) : error C2065: 'name' : undeclared identifier
c:\documents and settings\ee181\desktop\cpp1.cpp(69) : error C2065: 'last' : undeclared identifier
c:\documents and settings\ee181\desktop\cpp1.cpp(69) : error C2146: syntax error : missing ';' before identifier 'name'
c:\documents and settings\ee181\desktop\cpp1.cpp(69) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
c:\documents and settings\ee181\desktop\cpp1.cpp(71) : error C2065: 'cant' : undeclared identifier
c:\documents and settings\ee181\desktop\cpp1.cpp(74) : error C2065: 'data' : undeclared identifier
c:\documents and settings\ee181\desktop\cpp1.cpp(74) : error C2109: subscript requires array or pointer type
c:\documents and settings\ee181\desktop\cpp1.cpp(74) : error C2065: 'toupper' : undeclared identifier
c:\documents and settings\ee181\desktop\cpp1.cpp(74) : error C2109: subscript requires array or pointer type
c:\documents and settings\ee181\desktop\cpp1.cpp(74) : error C2106: '=' : left operand must be l-value
c:\documents and settings\ee181\desktop\cpp1.cpp(76) : error C2065: 'strcmp' : undeclared identifier
c:\documents and settings\ee181\desktop\cpp1.cpp(76) : error C2065: 'array' : undeclared identifier
c:\documents and settings\ee181\desktop\cpp1.cpp(76) : error C2109: subscript requires array or pointer type
c:\documents and settings\ee181\desktop\cpp1.cpp(76) : error C2228: left of '.name' must have class/struct/union type
c:\documents and settings\ee181\desktop\cpp1.cpp(76) : error C2143: syntax error : missing ';' before '&&'
c:\documents and settings\ee181\desktop\cpp1.cpp(77) : error C2143: syntax error : missing ';' before '{'
c:\documents and settings\ee181\desktop\cpp1.cpp(7 : error C2109: subscript requires array or pointer type
c:\documents and settings\ee181\desktop\cpp1.cpp(7 : error C2059: syntax error : '('
c:\documents and settings\ee181\desktop\cpp1.cpp(85) : error C2228: left of '.cout' must have class/struct/union type
c:\documents and settings\ee181\desktop\cpp1.cpp(85) : error C2297: '<<' : illegal, right operand has type 'char [68]'
c:\documents and settings\ee181\desktop\cpp1.cpp(86) : error C2146: syntax error : missing ';' before identifier 'name'
c:\documents and settings\ee181\desktop\cpp1.cpp(86) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
c:\documents and settings\ee181\desktop\cpp1.cpp(91) : error C2109: subscript requires array or pointer type
c:\documents and settings\ee181\desktop\cpp1.cpp(91) : error C2109: subscript requires array or pointer type
c:\documents and settings\ee181\desktop\cpp1.cpp(91) : error C2106: '=' : left operand must be l-value
c:\documents and settings\ee181\desktop\cpp1.cpp(93) : error C2109: subscript requires array or pointer type
c:\documents and settings\ee181\desktop\cpp1.cpp(93) : error C2228: left of '.name' must have class/struct/union type
c:\documents and settings\ee181\desktop\cpp1.cpp(93) : error C2143: syntax error : missing ';' before '&&'
c:\documents and settings\ee181\desktop\cpp1.cpp(94) : error C2143: syntax error : missing ';' before '{'
c:\documents and settings\ee181\desktop\cpp1.cpp(95) : error C2109: subscript requires array or pointer type
c:\documents and settings\ee181\desktop\cpp1.cpp(95) : error C2059: syntax error : '['
c:\documents and settings\ee181\desktop\cpp1.cpp(102) : error C2228: left of '.cout' must have class/struct/union type
c:\documents and settings\ee181\desktop\cpp1.cpp(102) : error C2297: '<<' : illegal, right operand has type 'char [68]'
c:\documents and settings\ee181\desktop\cpp1.cpp(103) : error C2146: syntax error : missing ';' before identifier 'name'
c:\documents and settings\ee181\desktop\cpp1.cpp(103) : warning C4552: '>>' : operator has no effect; expected operator with side-effect
c:\documents and settings\ee181\desktop\cpp1.cpp(10 : error C2109: subscript requires array or pointer type
c:\documents and settings\ee181\desktop\cpp1.cpp(10 : error C2109: subscript requires array or pointer type
c:\documents and settings\ee181\desktop\cpp1.cpp(10 : error C2106: '=' : left operand must be l-value
c:\documents and settings\ee181\desktop\cpp1.cpp(110) : error C2109: subscript requires array or pointer type
c:\documents and settings\ee181\desktop\cpp1.cpp(110) : error C2228: left of '.name' must have class/struct/union type
c:\documents and settings\ee181\desktop\cpp1.cpp(110) : error C2143: syntax error : missing ';' before '&&'
c:\documents and settings\ee181\desktop\cpp1.cpp(111) : error C2143: syntax error : missing ';' before '{'
c:\documents and settings\ee181\desktop\cpp1.cpp(112) : error C2109: subscript requires array or pointer type
c:\documents and settings\ee181\desktop\cpp1.cpp(112) : error C2059: syntax error : '='
c:\documents and settings\ee181\desktop\cpp1.cpp(125) : error C2228: left of '.cout' must have class/struct/union type
c:\documents and settings\ee181\desktop\cpp1.cpp(125) : error C2297: '<<' : illegal, right operand has type 'char [12]'
c:\documents and settings\ee181\desktop\cpp1.cpp(131) : error C2297: '<<' : illegal, right operand has type 'char [30]'
Error executing cl.exe.

Cpp1.obj - 71 error(s), 4 warning(s)
  #19  
Old 04-May-2005, 15:56
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough
That's what I like to see, code to cut and paste and an errorlog.

To start with, you have a block of code that does not make any sense to the compiler.
Quote:
Originally Posted by marita
CPP / C++ / C Code:
fp.open

for (i=0; i < /* quantity of objects in the file*/ ; i++)
f= a.getData(fp)
arreglo [i] = f;



//FUNCTION GETDATA

PhoneBook.getData()
{
  objeto a;

  fp >> a.name 
    return a;
}

One thing to keep in mind when you are posting code is to copy and paste your code EXACTLY as you are working on it. It seems there is some discrepency between your errors and posted code.

Luckily, I like troubleshooting. Your first error and my first error (after copying your posted code) are as follows:
Code:
// Your compiler error output c:\documents and settings\ee181\desktop\cpp1.cpp(26) : error C2143: syntax error : missing ';' before '.' c:\documents and settings\ee181\desktop\cpp1.cpp(26) : error C2501: 'fp' : missing storage-class or type specifiers c:\documents and settings\ee181\desktop\cpp1.cpp(26) : error C2143: syntax error : missing ';' before '.' // My compiler error output maritaPhoneBook.cpp:18: error: expected constructor, destructor, or type conversion before '.' token maritaPhoneBook.cpp:18: error: expected `,' or `;' before '.' token

The compiler is trying to make sense out of this and not having much luck. There are other related errors but let's just get rid of them by commenting out the offending block for the time being. You have a comment (c-style /**/) that I changed to '//' for now so I could comment out the entire block.

Saving a compiling that should give you this as your first error and the rest should be the same as you posted.
Code:
c:\documents and settings\ee181\desktop\cpp1.cpp(54) : error C2065: 'cout' : undeclared identifier

This is telling you that cout is currently nothing. It is not a way to output to the console, in fact, you could probably declare it as a variable or function at this point. Not that it would help anything, my point is, cout means nothing yet. So how do we fix that.

First off, how do you add something that is not defined and/or implemented in your own code. Ah ha!
CPP / C++ / C Code:
#include <something>
// or
#include "something"

Anything starting with the pound sign is a compiler directive. That is to say, those lines are telling the compiler (or some sort of preprocessor) something about our code. In this case we want to include the file that lets us use cout. That would be <iostream>. So at the top of the file add the line:
CPP / C++ / C Code:
#include <iostream>
Now, there are two ways (that I know of) to include things. One is to surround them with < some.file >. This, as one of the members here likes to say, "Looks in the magic places on your computer." I like that line very much. What it means is, "I will look in all the include paths that I can find in a linear manner until I find what I am looking for." Don't worry if you don't know what that means. If you can compile a hello_world example your compiler knows where to look.
The other is to use double quotes instead of less than greater than. This should look in the directory you are in for the file although it may then go looking in the magic places. As the same unnamed quoted member above might say,
"Your milage may vary."

So now the usefulness of iostream is now added to your program. But wait you say, no errors were removed when I tried to recompile. Oh, that is because we forgot to say what if anything we wanted to use from iostream. Now, I could wander off into an explanation of namespaces but if you are really interested in that rot use google or a text or something. I will just say that if you don't have a using somewhere, you aren't using anything. Add the following to the top of your file.
CPP / C++ / C Code:
#include <iostream>
using namespace std;

That reduces the number of errors quite considerably. But you really don't know why yet, do you? What we have done is allowed use by our program of anything (including the kitchen sink) that exists in the standard namespace. That is where c++ sticks pretty much everthing it might possibly need. Kind of like packing six suitcases when you are going to stay overnight at a friend's house. A little bit of overkill and you really don't learn anything by it. So, to get down to just a backpack of things we will only declare our intention to use the things we are using. To do this we will change the using a little. The standard namespace is referred to with the scope resolution of
Code:
std::
and our new code looks like this:
CPP / C++ / C Code:
#include <iostream>
using std::cout;
As you see, you have more errors than when using the entire std namespace. Ahh, but have you learned anything yet? By comparing the two sets of errors you can see the lines that refer to endl and cin are the ones. Treat them the same way you did cout and they will be gone for good.

That brings my next error to be this line:
CPP / C++ / C Code:
    cin >> name >> last name;
and the error
Code:
// Your errors c:\documents and settings\ee181\desktop\cpp1.cpp(69) : error C2065: 'name' : undeclared identifier c:\documents and settings\ee181\desktop\cpp1.cpp(69) : error C2065: 'last' : undeclared identifier // My errors maritaPhoneBook.cpp:65: error: `name' undeclared (first use this function) maritaPhoneBook.cpp:65: error: (Each undeclared identifier is reported only once for each function it appears in.) maritaPhoneBook.cpp:65: error: `last' undeclared (first use this function) maritaPhoneBook.cpp:65: error: expected `;' before "name"

Now we are in the meat of it. These variables you want to use need to be declared locally in main.

Enough for now, fix the errors you can, post questions and get this thing working. Please, post your EXACT code you are using to compile with your next set of questions and your EXACT errors as you did above. My only suggestion is to enclose the error codes in the [code] with the appropriate [/ code] to keep the smilies out. That is how the generic code sections were created in my post.

Mark
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
  #20  
Old 05-May-2005, 06:03
cable_guy_67's Avatar
cable_guy_67 cable_guy_67 is offline
Senior Member
 
Join Date: Oct 2004
Location: Nescopeck, PA
Posts: 1,109
cable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the roughcable_guy_67 is a jewel in the rough
Apparently I wasn't paying close enough attention in class yesterday. I didn't register that you had changed the names of the PhoneBook data members. So declaring them in main is not what you want to do.

Quote:
Originally Posted by marita
CPP / C++ / C Code:
private:
  char name;
  char lastname;
  int areacode;
  int phone;

PhoneBook::name and PhoneBook::lastname need to have an object to work on. In the older version of your code they were char arrays. Now they are just a char. I think you must want an array so you can store the names not just the first character?

In main, you need to create at least one variable of type PhoneBook to have access to the members. In the last code it was array[5]. That looked like the one that you wanted to declare dynamically using new once you get things under way. Look back at the old code and see how you were doing it. One thing to keep in mind as you learn is the thing I have been stressing, if you add a little bit at a time so you know the structure of your program is at least on the surface correct it is easier to find problems and implement new code without having to fight with 50 errors at a time.

You seem to have the basis for your menu loop set up. It is not quite correct yet but the idea is sound. Once you enter the menu you loop until you get an option or quit. Once again though, you don't have a PhoneBook object, you haven't read in your file nor have you even declared an intention to use it. You should be able to get that code from the older version of your program and add it to the new one with the menu.

Mark

EDIT:
One last thing. In order to get your code to compile (without correcting it myself anyhow) I commented out the body of your switch statements and replaced them with a single cout.
CPP / C++ / C Code:
switch(option)
{
  case 1:
    cout << "This is case 1" << endl;
/*        cout << "Enter the name and last name of the person you would like to edit: ";
        cin >> name >> last name;

        for (i=0; i < cant; i++)
        {
            for (int i =0; i<10; i++)
            data [i] = toupper (data[i]);

            if (strcmp (name, array [i].name)) && (strcmp (lastname, array [i].lastname))
            {
              array[i].()
            }
        }
*/        break;

I also did this with case 2 and 3. After compiling and running I still can't choose any options. There is also an error in your while condition that is easy to catch. The problem is you are reading in a char but not testing for a char. To check against a char you need to do something like:
CPP / C++ / C Code:
      case '1':
Using this same idea you can correct your loop to handle checking your char option against the char you want.

Simply put:
CPP / C++ / C Code:
cout << "Input Please" << endl;
cin >> option;
switch(option)
{
  case '1':
    cout << "This is case 1" << endl;
    break;
  case '2':
    cout << "This is case 2" << endl;
    break;
  default:
    cout << "This is default case" << endl;
    // break not needed since the fall through case is last
    // you could put it here though.  Effect is the same.
    break;
}

That essentially constitutes your do ... while loop in main.
__________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work."
--Thomas Alva Edison
"Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety."
--Benjamin Franklin
"A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes."
--Hugh Downs
Last edited by cable_guy_67 : 05-May-2005 at 06:42.
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

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

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:12.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.