Solved

code check please

Posted on 2004-09-23
3
223 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

0
Comment
Question by:edelossantos
  • 2
3 Comments
 
LVL 16

Assisted Solution

by:PaulCaswell
PaulCaswell earned 500 total points
ID: 12134638
So what works and what doesnt?

Paul
0
 
LVL 16

Accepted Solution

by:
PaulCaswell earned 500 total points
ID: 12134805
I am not terribly familliar with make files but this looks iffy:

     :{CPP} -c ${CFLAGS} $<

I'd suspect it should be

     {CPP} -c ${CFLAGS} $<

Paul
0
 

Author Comment

by:edelossantos
ID: 12134994
Finally....beautiful....that did it.  This one was tough and gave me a migrane and a lot of frustration.  Del
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

803 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