Hello can someone help me with my errors? I cant figure them out. There were alot more but i fixed those. (im on mandrake 9.1 using gcc)
first here are the errorsentry.hQuote:
addressbook.cpp: In function `void StartStuff()':
addressbook.cpp:52: invalid type argument of `unary *'
addressbook.cpp: In function `void CreateNew()':
addressbook.cpp:106: `Entries' undeclared (first use this function)
addressbook.cpp:106: (Each undeclared identifier is reported only once for each
function it appears in.)
entry.cpp:9: parse error before `char'
entry.cpp:12: ISO C++ forbids declaration of `home' with no type
entry.cpp:12: `Home' was not declared in this scope
entry.cpp:13: ISO C++ forbids declaration of `mobile' with no type
entry.cpp:13: `Mobile' was not declared in this scope
entry.cpp:15: `filename' was not declared in this scope
entry.cpp:17: syntax error before `<<' token
entry.cpp:18: syntax error before `<<' token
entry.cpp:19: syntax error before `<<' token
entry.cpp:21: syntax error before `.' token
entry.cpp:25: destructors must be member functions
entry.cppCode:// the 'entry' class used for each entry
// in the address book
//
class entry
{
public:
entry(char Name[100], int Home, int Mobile, char filename[100]); ~entry();
protected:
char name[100]; // name
int home; // home number
int mobile; // mobile number
}; // end entry class
addressbook.cpp // main dudeCode:// entry class constructor/destructor
//
#include "entry.h"
#include <fstream>
using namespace std; // for lame fstream include *sigh*
entry(char Name[100], int Home, int Mobile, char filename[100])
{
name = Name;
home = Home;
mobile = Mobile;
ofstream outfile(filename);
outfile << name << endl;
outfile << home << endl;
outfile << mobile << endl;
outfile.close();
}
~entry()
{
// not too much
}
Code:// address book program: stores name, home and mobile phone numbers
//
// includes
#include "entry.h" // isolated cause its cool
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
// prototypes
void StartStuff();
void Menu();
void CreateNew();
void Search();
// globals
int entries; // number of database entries (extracted from the index.dat file)
char *entries_str; // string version of entries integer
//
using namespace std;
// enter main dude
int main()
{
cout << "Address Book testing dude\n\n";
StartStuff(); // get everyhting read to use the prog
Menu(); // show menu; bla bla
cout << endl;
return 0;
}// end main()
// start everything and get it ready
void StartStuff()
{
ifstream infile("index.dat");
infile >> entries_str;
entries = atoi(entries_str); // change to int + store it in 'entries'
infile.close();
entry* Entries = new entry[*entries];
}// end StartStuff()
// for user to select what to do in the program
void Menu()
{
int choice = 0;
cout << "1. Create new entry\n"
<< "2. Search by name\n\n";
cout << "> ";
cin >> choice;
switch(choice)
{
case 1:
CreateNew();
break;
case 2:
Search();
break;
default:
cout << "Error. Chose a number from the menu...\n";
break;
}
}// end Menu()
// create new entry in database; this is where the magic happens
void CreateNew()
{
char filename[100];
char tempName[100];
int tempHome = 0;
int tempMobile = 0;
strcpy(filename, entries_str);
strcat(filename, ".dat");
ofstream newFile(filename);
cout << "Enter the person's name: ";
cin >> tempName;
cout << "\nEnter the person's home phone number: ";
cin >> tempHome;
cout << "\nEnter the person's mobile phone numnber: ";
cin >> tempMobile;
entry newEntry(tempName, tempHome, tempMobile, filename); // new entry being created of class type 'entry'
Entries[entries + 1] = newEntry;
}// end CreateNew()