473,499 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help on simple left brace error

1 New Member
C:\VC\Src\5060309482_6\6.cpp(131) : fatal error C1075: end of file found before the left brace '{' at 'C:\VC\Src\5060309482_6\6.cpp(76)' was matched
Error executing cl.exe.







//seqlist.h



#include <math.h>
#include <iostream.h>

class SeqList
{
private:
char *elem;
int length;
int MaxSize;
public:



void Clear( )const;
bool IsEmpty ( ) const {return (length==0);};
bool IsFull ( ) const { return (length==MaxSize);
int Length ( ) const;
char Get ( int i ) const;
int Find (char e ) const;
int Insert (int i, char e );
char Delete (int i );
};

SeqList::SeqList(int size):
{

elem = new char[size];
if (!elem) cout<<"there is no space in memory"<<endl;
else {length=0; MaxSize = 100-1;}

}

SeqList::SeqList():
{
elem = new char[10];
if (!elem) cout<<"there is no space in memory"<<endl;
else {length=0; MaxSize = 100-1; }

}

SeqList::~SeqList ( )
{
delete [ ]elem;
}


void SeqList::Clear()
{
length=0;
}


int SeqList::Length ( ) const
{
return length+MAXB;
}

char SeqList::Get ( int i ) const
{
if ((i>0) && (i<=length)) return elem[i];
else { cout <<"i is not correct ! "<<endl;return '#';
}
}

int SeqList::Find ( char e ) const
{
elem[0]= e; int i = length;
while (elem[i] != e ) i--;
return i;
}

int SeqList::Insert (int i, char e)
{
if ((i<1) || (i>length+1))
{
cout<<"i is not correct"<<endl;
return 0;
if (MaxSize == length)

{
cout<<"no space for new item"<<endl;
return 0;
}
for (int j=length; j>=i; j--)
elem[j+1]=elem[j];
elem[i]=e;
length++;
return 1;
}

char SeqList::Delete (int i )
{
if ((i<1) || (i>length))
cout<<"i is not correct"<<endl;

char e=elem[i];

for (int j=i; j<length; j++) elem[j]=elem[j+1];
length--;
return e;
}
void main()
{
SeqList chlist(10);
char ctemp;
int i, n;
int result;
cout<<"number of the elements:";
cin>>n;
cout<<"input the elements:";
for (i=1; i<=n; i++)
{ cin>>ctemp; chlist.Insert(i, ctemp); }
cout<<endl;
ctemp=chlist.Delete(1);
result = chlist.Insert(chlist.Length()/2+1, ctemp);
if (result==0) cout<<"fail to insert the element"<<endl;
else
cout<<"output the elements:"<<output the elements()<<endl;
for (i=1; i<=chlist.Length(); i++)
cout<<chlist.Get(i);
cout<<endl;





}
Jul 1 '07 #1
7 1506
Soneji
36 New Member
The original problem you noted was from two missing braces.
One in the class, and another in a function definition.

I fixed those, and a ton of other problems came up.

I couldn't fix the whole thing, because I wasn't sure about some things.

I did go through it and comment the crap out of it for you.

Maybe you can look through the comments, and fix it based on my notes.

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <math.h>
  3. #include <iostream.h>
  4.  
  5. class SeqList
  6. {
  7.     private:
  8.                char *elem;   
  9.                int length;   
  10.             int MaxSize;  
  11.     public:
  12.  
  13. // You don't have the constructors or destructor declared in the class.
  14. //   You can't define them below without declaring them here first.
  15.  
  16. // Const means you won't alter any values with the function... 
  17.             void Clear( ) const;
  18. // But in the definition for this function, you alter 'length'.
  19. // ( Remove 'const' from the 'Clear' function. )
  20.  
  21.             bool IsEmpty ( ) const {return (length==0);};
  22. // added closing brace to the end of the line below.
  23.             bool IsFull ( )     const { return (length==MaxSize); } 
  24.             int  Length ( ) const;
  25.             char Get ( int i ) const;     
  26.             int  Find (char e ) const;  
  27.             int  Insert (int i, char e );    
  28.                char Delete (int i );           
  29.   };
  30.  
  31. // Constructor not declared. ( See above )
  32. SeqList::SeqList(int size): // What's the colon for?
  33. //  You don't have a list of intializers here.     
  34.   {                                
  35.  
  36.             elem = new char[size];            
  37.           if (!elem) cout<<"there is no space in memory"<<endl;    
  38.           else {length=0;     MaxSize = 100-1;}
  39.  
  40.   }
  41. // Constructor not declared. ( See above )
  42. SeqList::SeqList():  // Again with the colon.  What are you trying to do?
  43.   {
  44.           elem = new char[10];            
  45.           if (!elem) cout<<"there is no space in memory"<<endl;    
  46.           else {length=0;     MaxSize = 100-1; }
  47.  
  48. }
  49. // Destructor not declared. ( See above )
  50. SeqList::~SeqList ( ) 
  51. {
  52. delete [ ]elem; 
  53. }
  54.  
  55.  
  56. void SeqList::Clear()  // ( See start of this comment in the class above )
  57. {
  58.     length=0; // See? You assign 0 to 'length'.
  59.  }    // You're "altering" the length variable.  This is a no-no with const.
  60.  
  61.  
  62. int SeqList::Length ( ) const
  63.  {
  64.       return length+MAXB;  // MAXB is undeclared.  
  65.  }                       // Can't use it till you declare it. 
  66.  
  67.  
  68. char SeqList::Get ( int i ) const
  69.  {
  70.        if ((i>0) && (i<=length)) return elem[i];
  71.     else { cout <<"i is not correct ! "<<endl;return '#';
  72.     } 
  73.   }
  74.  
  75. int SeqList::Find ( char e ) const
  76.      elem[0]= e;  int i = length;   
  77.      while (elem[i] != e ) i--;      
  78.      return i;                      
  79. }
  80.  
  81. int SeqList::Insert (int i, char e) 
  82. {
  83. if ((i<1) || (i>length+1)) 
  84. {
  85.         cout<<"i is not correct"<<endl;
  86.         return 0;    
  87.     if (MaxSize == length) 
  88.  
  89.     { 
  90.         cout<<"no space for new item"<<endl;
  91.         return 0; 
  92.     }
  93.         for (int j=length; j>=i; j--) 
  94.        elem[j+1]=elem[j];
  95.     elem[i]=e;    
  96.     length++;        
  97.     return 1;        
  98.  }  // *************************
  99. }   // Added another brace here.
  100.     // *************************
  101. char SeqList::Delete (int i ) 
  102. {
  103.     if ((i<1) || (i>length)) 
  104.         cout<<"i is not correct"<<endl;
  105.  
  106.          char e=elem[i];
  107.  
  108.       for (int j=i; j<length; j++)  elem[j]=elem[j+1];
  109.     length--;        
  110.     return e;        
  111. }
  112. void main()  // This should be 'int', not void.
  113. {
  114.     SeqList chlist(10);
  115.         char ctemp;
  116.         int i, n;
  117.         int result;
  118.         cout<<"number of the elements:";
  119.         cin>>n;
  120.         cout<<"input the elements:";  
  121.         for (i=1; i<=n; i++)
  122.             { cin>>ctemp;    chlist.Insert(i, ctemp); }    
  123.         cout<<endl;
  124.         ctemp=chlist.Delete(1);    
  125.         result = chlist.Insert(chlist.Length()/2+1, ctemp);
  126.         if (result==0) cout<<"fail to insert the element"<<endl;
  127.         else 
  128.             cout<<"output the elements:"<<output the elements()<<endl;
  129. // What are you trying to do with: "output the elements()"  ???
  130. // You don't have a function named that, and if you did, it wouldn't work
  131. //    without underscores between the names.
  132.             for (i=1; i<=chlist.Length(); i++)
  133.                 cout<<chlist.Get(i);                                   
  134.             cout<<endl;                                
  135. }
  136.  
Not sure if this will be any help, but I hope it is.

Good luck! :)
-Soneji
Jul 1 '07 #2
JosAH
11,448 Recognized Expert MVP
@OP: please don't double post. Your other (identical) thread didn't contain replies
yet and I removed it; please keep one problem in one thread only.

kind regards,

Jos

ps. use [ code ] ... [ /code ] tags when you post code. It makes it much more
readable; see the other reply for an example.
Jul 1 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
You have problem here:
char SeqList::Get ( int i ) const
{
if ((i>0) && (i<=length)) return elem[i];
else { cout <<"i is not correct ! "<<endl;return '#';
}
}
The semi-colon after your "if" should not be there.
Jul 1 '07 #4
Soneji
36 New Member
You have problem here:
Expand|Select|Wrap|Line Numbers
  1. Originally Posted by medetali
  2. char SeqList::Get ( int i ) const
  3. {                                          // -Soneji
  4. if ((i>0) && (i<=length)) return elem[i];  // return elem[i];  :)
  5. else { cout <<"i is not correct ! "<<endl;return '#';
  6. }
  7. }
  8.  
The semi-colon after your "if" should not be there.

Uh... weakness, that semicolon SHOULD be there. There's a return statement after that 'if' statement.

Without the semicolon, it won't compile.

:)

If I'm wrong on this, call me on it. ;)

-Soneji
Jul 2 '07 #5
r035198x
13,262 MVP
I think you need a brace here

Expand|Select|Wrap|Line Numbers
  1.              bool IsFull ( )     const { return (length==MaxSize);
P.S It is a good idea sometimes to have one statement per line.
Jul 2 '07 #6
weaknessforcats
9,208 Recognized Expert Moderator Expert
Uh... weakness, that semicolon SHOULD be there. There's a return statement after that 'if' statement.

Without the semicolon, it won't compile.
You're right. I hate code like this. It doesn't take much effort to
Expand|Select|Wrap|Line Numbers
  1. if ((i>0) && (i<=length))
  2. {  
  3.    return elem[i];  // return elem[i];  :)
  4. }
  5. else
  6.    cout <<"i is not correct ! "<<endl;return '#';
  7.  
  8. }
  9.  
Jul 2 '07 #7
Soneji
36 New Member
LOL!

I know what you mean.

I've still got eye-strain from going through it the first time. :)

Lates!
-Soneji
Jul 3 '07 #8

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

Similar topics

0
3380
by: abcd | last post by:
kutthaense Secretary Djetvedehald H. Rumsfeld legai predicted eventual vicmadhlary in Iraq mariyu Afghmadhlaistmadhla, kaani jetvedehly after "a ljetvedehg, hard slog," mariyu vede legai pressed...
5
1875
by: Danny Anderson | last post by:
Hola- I didn't get any responses on a previous post, so I am trying to reword my problem and post compile-able code that exhibits the behavior I am describing. On the second iteration of the...
6
2857
by: Jamal | last post by:
I am working on binary files of struct ACTIONS I have a recursive qsort/mergesort hybrid that 1) i'm not a 100% sure works correctly 2) would like to convert to iteration Any comments or...
6
2318
by: kaosyeti | last post by:
is there a way to create simple help file that i plan on linking to a command button on a form using what's already in access? i will probably be giving out this db that i've written to a number...
6
2664
by: toch3 | last post by:
i am writing a c program that is basically an address book. the only header we are using is #include<stdio.hwe are to use a global array, loops, and pointers. we are to have a menu at the...
5
7248
by: singhm | last post by:
Anybody know how to fix this?????????? ERROR: 1>c:\cs 140\assignment 5\assignment 5\main.cpp(88) : fatal error C1075: end of file found before the left brace '{' at 'c:\cs 140\assignment...
3
1484
by: shawnews | last post by:
Hi, I try to apply a simple tag to an image like that: <td><img src="../images/lower-left-corner.png" alt="lower-left-corner" width="26" height="19" class="right-middle" /></td> the css-tag...
2
1953
by: GC2006 | last post by:
//Error 1 error C2601: 'computeBestHotelBestMonth' : local function definitions are illegal e:\project 3\prj 3b.cpp 90 //Error 2 fatal error C1075: end of file found before the left brace '{' at...
0
5518
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
6
2334
by: Bryan Parkoff | last post by:
I want to know the best practice to write on both C / C++ source codes. The best practice is to ensure readable. Should left brace be after function or if on the same line or next line. For...
0
7132
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7009
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
7223
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...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.