Solved

HELP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Posted on 2004-09-23
6
257 Views
Last Modified: 2010-04-01
Need help with lab homework:

# Makefile:
#        It uses the C++ Compiler with all warnings and
#        full debugging; will create a single executable called 'main'
# ---------------------------------------------------------------
# Note: If you want to use the g++ compiler on pegasus or helios
# uncomment the g++ lines and comment the Digital Unix lines

# the Digital Unix C++ compiler needs these lines:
CPP = cxx
CFLAGS = -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall

# the g++ compiler on pegasus and helios needs these lines:
# CPP = g++
# CFLAGS = -DPOSIX_4D9 -w -g

# link in the math library
LFLAGS = -lm

RM = rm -f
# ----------------------------------------------------------------
# Explanation of macros:
#     $< is any dependent file which is out of file1
#     $* is the target's basename (without extension)
#     $@ is the target's fullname
#
# add suffix .cpp since it is not a default with make util
.SUFFIXES:     .cpp .o
#
# implicit rule for compilation only:
.cpp.o:
      :{CPP} -c ${CFLAGS} $<

OFILES=          main.o

# dependencies
#
default:     main    
#
main:           $(OFILES)
      {CPP} ${CFLAGS} ${LFLAGS} $(OFILES) -o $@

main.o:          main.cpp

#
clean:
      ${RM} *.o
      ${RM} core
#
veryclean:     clean
      ${RM}  main  

#include <iostream>  
using namespace std;

#define CHUNK_SIZE 100

template <class item_t>
class Stack_t
{
    item_t*  items;
    int      top;

public:
    Stack_t() : items(NULL), top(0) {}
    ~Stack_t() { delete [] items; }
    void push(item_t item)
    {
        if (top%CHUNK_SIZE == 0)
        {
            item_t* nitems = new item_t[top + CHUNK_SIZE];
            if (items != NULL)
            {
                for (int i = 0; i < top; i++)
                    nitems[i] = items[i];
            }
            delete []items;
            items = nitems;
        }
        items[top++] = item;
    }
    bool pop(item_t& item)
    {
        if (top == 0)
        {
            return false;
        }
        item  = items[--top];
        if (top%CHUNK_SIZE == 0)
        {  
            item_t* nitems = NULL;
            if (top > 0)
            {
                nitems = new item_t[top];
                for (int i = 0; i < top; i++)
                    nitems[i] = items[i];
            }
            delete []items;
            items = nitems;
        }
        return true;
    }                            
    bool empty() { return top == 0; }
};


int main()
{
    const int SIZE = 100;
   
    Stack_t<char> S;
    char input[SIZE]    = { 0 };
    char S_output[SIZE] = { 0 };
    int i,length;
   
    cout << "Enter a palindrome> ";
    gets(input);
    for(i=0;input[i]!=NULL;i++)
    {
        S.push(input[i]);
    }
   
    length = strlen(input);  
    for(i=0;i<length;i++)
    {
        S.pop(S_output[i]);
       
        if(input[i]!=S_output[i])
        {
            cout << endl << "The words are not palindrome" << endl;
            break;  
        }
       
        else // if(Q_output[i]==S_output[i])
            cout << S_output[i];
    }
    if (i >= length)
        cout << " is a palindrome" << endl;
   
    putchar('\n');

    Stack_t<int> Si;
    int inp;
    cout << "Enter a list of integers terminated by -1" << endl;
    for (i = 1; ; ++i)
    {
        cin >> inp;
        if (inp == -1)
            break;
        Si.push(inp);
    }

    int sum = 0;
    while (!Si.empty())
    {
        Si.pop(inp);
        sum += inp;
    }
    cout << "The sum of the numbers entered is " << sum << endl;
    return 0;
}

output:

[edeloss2@pegasus lab2]$ make veryclean
rm -f *.o
rm -f core
rm -f  main
[edeloss2@pegasus lab2]$ make
:{CPP} -c -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall  main.cpp
/bin/sh: :{CPP}: not found
make: *** [main.o] Error 1

****************************NEED THIS BEHAVIOR...SHOW ME OR TELL ME HOW!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Enter a palindrome: madam

                The word reversed is: madam

                Enter a list of integers followed by -1: 1 2 3 4 5 -1

                The sum of the numbers on the stack is: 15

OR IS THIS CODE LIKE THIS ALREADY....IF YOU HAVEN'T FIGURED IT OUT...I AM CLUELESS....PLEASE, PLEASE, ADVISE!!!



0
Comment
Question by:edelossantos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 

Author Comment

by:edelossantos
ID: 12134461
ANYONE OUTHERE....AN ANWER ONE WAY OR ANOTHER WOULD WORK!!!!!!
0
 
LVL 11

Assisted Solution

by:griessh
griessh earned 250 total points
ID: 12134753
Hi edelossantos,

It looks like you are working on pegasus. Check these line and change the settings:

> # Note: If you want to use the g++ compiler on pegasus or helios
> # uncomment the g++ lines and comment the Digital Unix lines

> # the Digital Unix C++ compiler needs these lines:
> CPP = cxx
> CFLAGS = -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall

> # the g++ compiler on pegasus and helios needs these lines:
> # CPP = g++
> # CFLAGS = -DPOSIX_4D9 -w -g


======
Werner
0
 
LVL 11

Accepted Solution

by:
avizit earned 250 total points
ID: 12134781
>>>:{CPP} -c -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall  main.cpp


>>>/bin/sh: :{CPP}: not found <<<<------------------look what this error is

and loook at your Makefile


.cpp.o:
     :{CPP} -c ${CFLAGS} $<


++++++++++++++++
if you cant figure it out , read this

http://www.eng.hawaii.edu/Tutor/Make/   




0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:edelossantos
ID: 12134855
# Makefile:
#        It uses the C++ Compiler with all warnings and
#        full debugging; will create a single executable called 'main'
# ---------------------------------------------------------------
# Note: If you want to use the g++ compiler on pegasus or helios
# uncomment the g++ lines and comment the Digital Unix lines

# the Digital Unix C++ compiler needs these lines:
#CPP = cxx
#CFLAGS = -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall

# the g++ compiler on pegasus and helios needs these lines:
 CPP = g++
 CFLAGS = -DPOSIX_4D9 -w -g

# link in the math library
LFLAGS = -lm

RM = rm -f
# ----------------------------------------------------------------
# Explanation of macros:
#     $< is any dependent file which is out of file1
#     $* is the target's basename (without extension)
#     $@ is the target's fullname
#
# add suffix .cpp since it is not a default with make util
.SUFFIXES:     .cpp .o
#
# implicit rule for compilation only:
.cpp.o:
      :{CPP} -c ${CFLAGS} $<

OFILES=          main.o

# dependencies
#
default:     main    
#
main:           $(OFILES)
      ${CPP} ${CFLAGS} ${LFLAGS} $(OFILES) -o $@

main.o:          main.cpp

#
clean:
      ${RM} *.o
      ${RM} core
#
veryclean:     clean
      ${RM}  main  

[edeloss2@pegasus lab2]$ make
:{CPP} -c -DPOSIX_4D9 -w -g  main.cpp
/bin/sh: :{CPP}: not found
make: *** [main.o] Error 1

0
 
LVL 11

Assisted Solution

by:avizit
avizit earned 250 total points
ID: 12134946
as i said

++++++++++++++++++++
# implicit rule for compilation only:
.cpp.o:
     :{CPP} -c ${CFLAGS} $<

+++++++++++++++++++++++++

the lines above has errors  find it and fix , its simple enough and you should be able to fix it.

also the errors says
>>>>/bin/sh: :{CPP}: not found


that should give you a hint ..


0
 

Author Comment

by:edelossantos
ID: 12135017
That did it...I got it...finally...this code as all codes exceeded my limitations; however, it runs beautifully and finally to expectations and specifications.  A million thanks.  Del
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question