MAX value of a subsequence sum

B

begum

i write a program about finding the max value of a subseqence in a
given sequence. i write but i finf lots of syntax mistakes and i
can't do them in correct. please help me.

Thanks;
Begum

here is the program

#include <iostream>
#include <conio.h>
#include <iomanip.h>
#pragma hdrstop
template <class someType>
class Sum
{
private:
someType arr[100];
public:
void add();
void get_sequence();
};
template <class someType>
void Sum<sumType>::add()
{
int i;
cout<<"****PLEASE GIVE A SUBSEQUENCE WHICH IS TO FIND THE MAX.
VALUE ****\n"<<endl;
cin>>"%d",&d>>endl;
}
template <class someType>
void Sum<sumType>::get_sequence()
{
int maxSum=0;
int thisSum=0;
int j;
for (j=0; j<101; j++)
{
thisSum +=a[j];
if (thisSum > maxSum)
{
maxSum = thisSum;
}
else if (thisSum < 0)
{
thisSum=0;
}
return maxSum;
}
}
void main ()
{
void add();
void get_sequence();
}
 
B

BobR

begum wrote in message
i write a program about finding the max value of a subseqence in a
given sequence. i write but i finf lots of syntax mistakes and i
can't do them in correct. please help me.
Thanks;
Begum

here is the program

#include <iostream>
#include <conio.h>

[ from a note in MinGW ]
/*
* conio.h
<snip copyright>
* Low level console I/O functions. Pretty please try to use the ANSI
* standard ones if you are writing new code.
*/
#include <iomanip.h>

You probably mean said:
#pragma hdrstop

Compiler specific. (?).
template <class someType> class Sum{
private:
someType arr[100];
public:
void add();
void get_sequence();
};
template <class someType>
void Sum<sumType>::add(){
int i;
cout<<"****PLEASE GIVE A SUBSEQUENCE WHICH IS TO FIND THE MAX.
VALUE ****\n"<<endl;
cin>>"%d",&d>>endl;

???? What the....?
You can't input to "%d" !!
You can't input to endl !!
[ You can't just mix/replace scanf syntax with iostreams. ]

Try:
cin >> i;
}
template <class someType>
void Sum<sumType>::get_sequence(){
int maxSum=0;
int thisSum=0;

// int j;

Unused except in 'for()', so, why don't you put it in the 'for()'?

// for (j=0; j<101; j++){
for (int j(0); j<101; ++j){
thisSum +=a[j];

There is NO 'a' anywhere!! Did you mean the 'arr[]' in your class?
if( thisSum > maxSum ){
maxSum = thisSum;
} // if(>)
else if( thisSum < 0 ){
thisSum=0;
} // else if(<)
return maxSum;

Sure you want to 'return' from inside your loop?
} // for(j)
} // Sum<sumType>::get_sequence() end
void main (){

Ahhh, I see now!! You are using code from the early 1980s!!

int main (){ // main() *always* returns an int!!

// void add();
// void get_sequence();
// [ those just declare some functions inside main. (and never define
them!) ]

Sum<int> sum;

sum.add();
sum.get_sequence();

return 0;

Fix all that and try again. OK?
[ I assume you'll have new questions. ]
 
D

Daniel T.

begum said:
i write a program about finding the max value of a subseqence in a
given sequence. i write but i finf lots of syntax mistakes and i
can't do them in correct. please help me.

Note the first error listed and the line number:

error: 'sumType' was not declared in this scope

points to:
template <class someType>
void Sum<sumType>::add() <---- points to here


Why do you think the compiler is telling you that 'sumType' is not
declared? (Meaning the compiler doesn't know what a 'sumType' is.

It took me longer than I'd care to admit to figure this one out. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top