473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Declaration syntax error

Im trying to write a program about a truck inventory with trucks coming and going and the amount in each one, but keep coming up with declaration syntax error.. Any help would be greatly appreciated. Im using Borland C++. Thanks


Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2. #include <iomanip.h>
  3. #include <stdlib.h>
  4. #include <conio.h>
  5. #include <string.h>
  6. #include <ctype.h>
  7.  
  8. #define max_trucks 50
  9.  
  10. class TRUCKS
  11. {
  12.     private :
  13.     int TRUCK_NUM;
  14.     int TRUCK_CAP;
  15.     int DON_ON_HAND;
  16.     static int NUM_TRUCKS;
  17.  
  18.     public :
  19.     TRUCK (int id, int don=0);
  20.     int ADD_TRUCK (int don);
  21.     int REMOVE_TRUCK (int don);
  22.     inline int GET_TRUCK_NUM () {return TRUCK_NUM;}
  23.     inline int GET_CAP () {return TRUCK_CAP;}
  24.     inline int GET_CONT () {return DON_ON_HAND;}
  25.     static int TOTAL_TRUCKS();
  26. };
  27.  
  28. int NUM_TRUCKS = 0
  29.     {
  30.     TRUCK_NUM = id;
  31.     CAP_ON_HAND = don;
  32.     TRUCK_CAP = 250;
  33.     ++NUM_TRUCKS;
  34.     }
  35.     TRUCK: :TRUCK ()
  36.     {
  37.         delete [] TRUCK_ID;
  38.     }
  39.     int TRUCK: :TOTAL_TRUCKS ()
  40.     {
  41.         return NUM_TRUCKS;
  42.     }
  43.  
  44.     TRUCK* create_truck ();
  45.     void display (TRUCKS&);
  46.     truck_table
  47.     {
  48.     void main ()
  49.  
  50.         create_truck,
  51.         truck_table;
  52.         int don_amt = 250,
  53.             result,
  54.             count = 0,
  55.             choice;
  56.             max_trucks;
  57.         char select = ' ';
  58.         char answer = ' ';
  59.  
  60.              [max_trucks];
  61.  
  62.         do
  63.         {
  64.             cout << "\n\nPlease choose a number from the menu below";
  65.             cout << "\n1. Add a truck";
  66.             cout << "\n2. Add donations to truck";;
  67.             cout << "\n3. Remove a Truck";
  68.             cout << "\n4. Display the trucks";
  69.             cout << "\n5. Quit the program";
  70.             cout << "\n\nPlease enter your selection now: ";
  71.             cin >> select;
  72.             clrscr ();
  73.  
  74.             switch (select)
  75.             {
  76.                 case '1':
  77.                     cout << "\nDo you want to add a truck to inventory?(Y/N): ";
  78.                     cin >> answer;
  79.                     while (toupper(answer) == 'Y' && count, max_trucks)
  80.                     {
  81.                         truck_table[count] = create_truck ();
  82.                         ++count;
  83.                         cout << "\nDo you want to add a truck to inventory?(Y/N): ";
  84.                         cin >> answer;
  85.                     }
  86.                     break;
  87.                 case '2':
  88.                     cout << "\nTo whick truck would you like to add donations? (1-50) : ";
  89.                     cin >> choice;
  90.                     if (choice < 1 || choice > count)
  91.                     {
  92.                         cout << "\n\nINVALID ENTRY!!! ";
  93.                         break;
  94.                     }
  95.                     else
  96.                     {
  97.                         cout << "\nPlease enter the amount of donations to add: ";
  98.                         cin >> don_amt;
  99.                         result = truck_table [choice - 1]->ADD_DON (don_amt);
  100.                         if (result < 0)
  101.                             cout << "\nERROR Truck capacity is not large enough!!!\n";
  102.                         else
  103.                             cout << "\nDonations added!!! ";
  104.                         break ;
  105.                     }
  106.                 case '3' :
  107.                     for (int x = 0; x < count; ++x)
  108.                         display (*truck_table [x]);
  109.                     break ;
  110.                 }
  111.             }
  112.             while (select != '4');
  113.                 cout << "\n\n\n\n                            THANK YOU";
  114.                 cout << "\n\n                            GOODBYE";
  115.             for (int x = 0; x < count; ++x)
  116.                 delete truck [x] ;
  117.         }
  118.  
  119.     TRUCK* create()
  120.     {
  121.         int truck_num,
  122.             donations + 0;
  123.         char name [80];
  124.  
  125.         TRUCK* truckptr;
  126.  
  127.         cout << "\nPlease enter the truck number: ";
  128.         cin >> truck_num;
  129.         cin.ignore (81, '\n');
  130.         cout << "\nPlease enter the amount of donations in truck: ";
  131.         cin >> donations;
  132.         cin.ignore (81, '\n');
  133.         clrscr ();
  134.         truckptr = new TRUCK(truck_num, donations);
  135.         cout << "\n\nTrucks in inventory : " truckptr->TOTAL_TRUCKS ();
  136.         return truckptr;
  137.     }
  138.  
  139.     void display (TRUCK& truck)
  140.     {
  141.         cout << "\n\nTruck num " << truck. GET_TRUCK_NUM ();
  142.         cout << "\nTruck capacity: " << truck. GET_CAP ();
  143.         cout << "\nDonations on hand: " << truck. GET_CONT ();
  144.     }
Mar 7 '10 #1
11 3303
Banfa
9,065 Expert Mod 8TB
It would greatly help us if you would post the exact errors you are getting and indicate on what lines of the posted listing they occur.
Mar 7 '10 #2
Banfa
9,065 Expert Mod 8TB
However I notice that

Line 10/19: constructor name does not match class name

Line 29: Ransom code not actually in a function

Line 10/39 Declaration/definition class name mismatch

Line 48: main returns int NOT void, not { indicating the start of the main function.

Line 50, 51, 56: Random symbols not defined anywhere else

Line 60: random array syntax not attached to any symbol name

Points on style

class TRUCK(S) it is unusual styling, though not strictly wrong, for a class name to be all in capital letters and similarly it is also unusual styling for all member names to be in capitals. In my company all caps is reserved for consts and static consts.

Line 119: The factory function to create a TRUCK could be and probably would be better being a static member function of the class TRUCK

Line 139: a function like this to output a TRUCK would be better off being a member of TRUCK, however an alternitive would be to make an iostream helper function that handles the truck type allowing

cout << truck;
Mar 7 '10 #3
newb16
687 512MB
Also, :: (two colons) in scope resolution, like Classname::Functionname().... should not have space between them.
Mar 7 '10 #4
declaration syntax errors are on line 29 and 47 thanks for help
Mar 8 '10 #5
In c++, main will have return type is int, you should mention as
int main( ),

Please try with, let us know, ur facing any other declaration error.
Mar 8 '10 #6
Banfa
9,065 Expert Mod 8TB
declaration syntax errors are on line 29 and 47 thanks for help
You are missing ; at the end of lines 28 and 46.

It is not uncommon for compiler errors to be reported on the first code line after then line with the error in it, particularly for things like missing ; and other syntax errors were the compiler can not tell there is a syntax error until it reads in the next bit of actual code.
Mar 8 '10 #7
putting ; at the end of 28 and 46 didnt make any difference acutally give me a 3rd error
Mar 9 '10 #8
Banfa
9,065 Expert Mod 8TB
You may want to consider fixxing all the other issues I raised in post #3 and that other people have pointed out.

It is not unheard of of a syntax error to be hiding someother error in the code that only shows up after fixing the syntax error.

Your compile process (as a beginner) show be
  1. Compile the code
  2. If there are no errors and warnings stop
  3. Fix the first error in compiler output the listing
  4. goto 1

Once you gain experience you can fix more than one error at step 3 because you will learn which messages can be ignored as a symptom of a previous error.
Mar 9 '10 #9
ok I have went step by step and started with part of the program and compiled it slowly as I went and still having issues, I am like at the point that I have changed things so much that I am now totally lost to what I am doing and writing..I do appreciate everyones help but gettin to frustrated..you would think it would be something simple that I am overlooking but i have sat at it too long and cant seem to see whats wrong Thanks all
Mar 10 '10 #10
Banfa
9,065 Expert Mod 8TB
If you have done a lot of changes I suggest you repost your code, remembering to put [code]...[/code] tags round it.
Mar 10 '10 #11
Can I ask if anyone has run this program and not have any errors?? If so what did you change in order for it to work? Thanks
Mar 10 '10 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

83
by: Alexander Zatvornitskiy | last post by:
Hello All! I'am novice in python, and I find one very bad thing (from my point of view) in language. There is no keyword or syntax to declare variable, like 'var' in Pascal, or special syntax in...
16
by: Bhushit Joshipura | last post by:
This post contains one question and one proposal. A. May I know why order of evaluation of arguments is not specified in C/C++? I asked a question in comp.lang.c++ for the following...
3
by: Michael Sgier | last post by:
Hello with the original code below I get the error: "forward declaration of `struct CPlayer'" class CPlayer; // what does this do? Instantiate the class CPlayer? // what's a forward...
7
by: Jacob Schmidt | last post by:
Could anyone correct the error in my logic here?: #include <stdio.h> #include <stdlib.h> main () { const char message1 = {"\nCurved portion of graph -- D.G.A.C.\ \n A B C"}; const char...
2
by: Nils Emil P. Larsen | last post by:
Hello I have read about a C shared library which I want to use in my C program. (It's a library to encode/decode packets from/to a serial bus running with the SNAP-protocol). Unfortunatly...
3
by: Wild Wind | last post by:
Hello, I made a post relating to this issue a while back, but I haven't received any answer, so here I am again. I am writing a mixed C++ dll which uses the following declaration: typedef...
4
by: Alan Foxmore | last post by:
Hi everyone, I'm new to C# and I was hoping I could get some clarification on the syntax for jagged and multidimensional arrays. Here is my question: The following syntax is correct for...
2
by: srikar | last post by:
Hi I am having a problem using typedef what does these declaration mean? typedef gtb(string_t, tt_type_enum) tt_type_table( &stringless, &stringequals ); typedef gtb(string_t,tt_qual_enum)...
10
by: fred.zakity | last post by:
Can someone please explain this function pointer declaration: float (* getptr (char opcode) ) (int, int); I'm confused by the syntax - I have not seen a function pointer with the extra...
11
by: mdh | last post by:
I decided to make a single file containing all the repetitive functions in K&R so that I could concentrate on the new discussions. This went along just fine, and with each new function, added the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.