code check

# Makefile:
#        It uses the C++ Compiler with all warnings and
#        full debugging; will create a single executable called 'main'
# ---------------------------------------------------------------
# the compiler
CPP = cxx
# compiler flags
CFLAGS = -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall
# linker flags to link in the libraries libm.a and libtask.a
LFLAGS = -lm -ltask
#
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 life.o util.o

HFILES=            life.h  util.h

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

main.o:            main.cpp life.h util.h
life.o:            life.cpp life.h util.h
util.o:            util.cpp util.h

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

// util.h
         
#ifndef UTIL_H  
#define UTIL_H  

#define NULL 0L

#define STDSCREEN 80        
#define DOWN 0                        
#define UP   1
#define END   0
#define START 1
#define FAIL    0
#define SUCCESS 1
#define MISS -1
#define HIT   1

   enum Error_code { success, fail, range_error, underflow, overflow, fatal,
                  not_present, duplicate_error, entry_inserted, entry_found,
                  internal_error };

   void clearScreen ();                    
   void clearTop();                        
   void clearBelowTop();                  
   void goTop();                              
   void topLine(const char * text = " "  );    
   void bottomLine (char * text = " ");  

   void hitAnyKey ();                    
   void flushInput ();                    
   void Warning(char *);                  
   void Error(char *);                    
   bool promptYesNo(char * prompt="");      
   void EatWhiteSpace(void);              

#endif

// util.cpp
         

#include <iostream>
using namespace std;

#include "util.h"

void clearScreen (void)
 
{
  cout << "\033[2J";          
  cout << "\033[;f";          
}

void clearTop()
{
  cout << "\033[0;0f" << "\033[0K";
}

void clearBelowTop()
{
  cout << "\033[1;0f" << "\033[1B" << "\033[J";
}

void goTop ()
{
  cout << "\033[0;0f";
}

void topLine(const char str[])
{
  cout << "\033[0;0f" << "\033[0K" << str;
}

void bottomLine (char * str)
{
  cout << "\033[23;0Hf" << "\033[2K" << str;
}

void hitAnyKey ()
{
   char ch;
   bottomLine ("Hit any key to continue...");
   cin.get(ch);
   clearScreen();
}

void flushInput ()
{
   char buff[81];
   if (cin)
      cin.getline(buff,80);    
}

void Warning(char *message)
{
   cerr << message;
}

void Error(char *message)
{
   cerr << message;
   exit(1);
}

void EatWhiteSpace()
{
    char ch;
    do {
      cin.get(ch);
    }
    while(isspace(ch));

    if(ch != EOF)
      cin.putback(ch);
}

bool promptYesNo(char * c)
{
   char ch;
   cout << c << " [y|n]?";
   do {
      cin.get(ch);  
      tolower(ch);
      } while (ch != 'y' && ch != 'n');
   return (ch == 'y');
}

// life.h
     
#ifndef LIFE_H
#define LIFE_H

const int maxrow=20, maxcol=60;// grid dimensions

class Life {

public:

  void initialize();
  void print();
  void update();

private:

  int grid[maxrow+2][maxcol+2];
  int neighbor_count(int row, int col);

};

#endif

//  life.cpp
//  definitions for Life class  

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

#include <time.h>

using namespace std;

#include "util.h"
#include "life.h"

int Life::neighbor_count(int row, int col)
{
  int i,j;
  int count=0;

  for(i=row-1; i<=row+1; row++)
     for(j=col-1; j<=col+1; J++)
       count+=grid[i][j];  
     count-=grid[row][col];

     return count;

}

void Life::update()
{
  int row, col;
  int new_grid[maxrow+2][maxcol+2];

  for(row=1; row<=maxrow; row++)
     for(col=1; col<=maxcol; col++)

        switch(neighbor_count(row, col) {
        case 2:
             new_grid[row][col]=grid[ro][col];
        break;

        case 3:
            new_grid[row][col]=1;
        break;

        default:
            new_grid[row][col]=0;

      }

  for(row=1; row<=maxrow; row++)
     for(col=1; col<=maxcol; col++)
      grid[row][col]=new_grid[row][col];

}

// main.cpp
 
// Conway's Game of Life

#include <iostream>
#include "util.h"
#include "life.h"

using namespace std;

int main() {

  Life configuration;
  instructions;
  configuration.initialize();
  configuration.print();

  cout << "Continue viewing new generations? " << endl;

  while(user_says_yes()) {
      
      configuration.update();
      configuration.print();

      cout << "Continue viewing new generations? " << endl;
   }

}

make output =

cxx -c -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall main.cpp
cxx: Error: main.cpp, line 9: name must be a namespace name
using namespace std;
----------------^
cxx: Error: main.cpp, line 14: identifier "instructions" is undefined
  instructions;
--^
cxx: Error: main.cpp, line 20: identifier "user_says_yes" is undefined
  while(user_says_yes()) {
--------^
cxx: Info: 3 errors detected in the compilation of "main.cpp".
make: *** [main.o] Error 1

edelossantosAsked:
Who is Participating?
 
avizitConnect With a Mentor Commented:
I think you misunderstood me

you dont have to type <TAB>

i meant you have to replace the space by the tab characater , which you can get by

deleting the spaces before ${CPP} -c ${CFLAGS} $<  so that the file looks like this

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

now take the cursor to the beginning of the line i.e

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

and then press the tab key ( if you are using vi youhave to be in insert mode )

so that now the file looks like

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

0
 
avizitCommented:
1)  in main() what does the line
 
   instructions;

do ?  there seems to be something wrong there ..


2)  you have to define "user_says_yes()"
or better still i think would be to make it as a character and read the value from the user in the main() itself , instead of making yet another function call
0
 
avizitCommented:
also as someone else pointed out , dont open new question if your problem is not solved in current one ... we end up having many questions all partially solved

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
avizitCommented:
1) you can have the while loop in main() as

char user_says_yes = 'y';
  while(user_says_yes == 'y') {

    configuration.update();
    configuration.print();

    cout << "Continue viewing new generations? " << endl;
    cin>>user_says_yes;
  }

you can make your own modification to accept both 'y' and "Y"

2) in life.cpp you have

for(i=row-1; i<=row+1; row++)
     for(j=col-1; j<=col+1; J++)

--> you have to change the 'J' to 'j'  

3)in life.cpp you have

 switch(neighbor_count(row, col) {
      case 2:

the switch ( is not properly closed

it should be
switch(neighbor_count(row, col))

4) in life.cpp you have
case 2:
        new_grid[row][col]=grid[ro][col];

that should be

   new_grid[row][col]=grid[row][col];

i.e 'row' and not 'ro'

......



0
 
edelossantosAuthor Commented:
I apologize about the multiple questions.  These are two different versions.  Del
0
 
edelossantosAuthor Commented:
//  life.cpp
//  definitions for Life class  

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

#include <time.h>

using namespace std;

#include "util.h"
#include "life.h"

void Life::initialize(){}
void Life::print(){}

int Life::neighbor_count(int row, int col)
{
  int i,j;
  int count=0;

  for(i=row-1; i<=row+1; row++)
     for(j=col-1; j<=col+1; j++)
       count+=grid[i][j];  
     count-=grid[row][col];

     return count;

}

void Life::update()
{
  int row, col;
  int new_grid[maxrow+2][maxcol+2];

  for(row=1; row<=maxrow; row++)
     for(col=1; col<=maxcol; col++)

        switch(neighbor_count(row, col)) {

        case 2:
             new_grid[row][col]=grid[row][col];
        break;

        case 3:
            new_grid[row][col]=1;
        break;

        default:
            new_grid[row][col]=0;
      }
      

  for(row=1; row<=maxrow; row++)
     for(col=1; col<=maxcol; col++)
      grid[row][col]=new_grid[row][col];

}

// life.h
     
#ifndef LIFE_H
#define LIFE_H

void instruction(){}
bool user_says_yes(){return(true);}

typedef int bool;
const bool false=0;
const bool true=1;

const int maxrow=20, maxcol=60;// grid dimensions

class Life {

public:

  void initialize();
  void print();
  void update();

private:

  int grid[maxrow+2][maxcol+2];
  int neighbor_count(int row, int col);

};

#endif

//  life.cpp
//  definitions for Life class  

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

#include <time.h>

using namespace std;

#include "util.h"
#include "life.h"

void Life::initialize(){}
void Life::print(){}

int Life::neighbor_count(int row, int col)
{
  int i,j;
  int count=0;

  for(i=row-1; i<=row+1; row++)
     for(j=col-1; j<=col+1; j++)
       count+=grid[i][j];  
     count-=grid[row][col];

     return count;

}

void Life::update()
{
  int row, col;
  int new_grid[maxrow+2][maxcol+2];

  for(row=1; row<=maxrow; row++)
     for(col=1; col<=maxcol; col++)

        switch(neighbor_count(row, col)) {

        case 2:
             new_grid[row][col]=grid[row][col];
        break;

        case 3:
            new_grid[row][col]=1;
        break;

        default:
            new_grid[row][col]=0;
      }
      

  for(row=1; row<=maxrow; row++)
     for(col=1; col<=maxcol; col++)
      grid[row][col]=new_grid[row][col];

}

// util.h
         
#ifndef UTIL_H  
#define UTIL_H  

#define NULL 0L

#define STDSCREEN 80        
#define DOWN 0                        
#define UP   1
#define END   0
#define START 1
#define FAIL    0
#define SUCCESS 1
#define MISS -1
#define HIT   1

   enum Error_code { success, fail, range_error, underflow, overflow, fatal,
                  not_present, duplicate_error, entry_inserted, entry_found,
                  internal_error };

   void clearScreen ();                    
   void clearTop();                        
   void clearBelowTop();                  
   void goTop();                              
   void topLine(const char * text = " "  );    
   void bottomLine (char * text = " ");  

   void hitAnyKey ();                    
   void flushInput ();                    
   void Warning(char *);                  
   void Error(char *);                    
   bool promptYesNo(char * prompt="");      
   void EatWhiteSpace(void);              

#endif

// util.cpp
         

#include <iostream>
using namespace std;

#include "util.h"

void clearScreen (void)
 
{
  cout << "\033[2J";          
  cout << "\033[;f";          
}

void clearTop()
{
  cout << "\033[0;0f" << "\033[0K";
}

void clearBelowTop()
{
  cout << "\033[1;0f" << "\033[1B" << "\033[J";
}

void goTop ()
{
  cout << "\033[0;0f";
}

void topLine(const char str[])
{
  cout << "\033[0;0f" << "\033[0K" << str;
}

void bottomLine (char * str)
{
  cout << "\033[23;0Hf" << "\033[2K" << str;
}

void hitAnyKey ()
{
   char ch;
   bottomLine ("Hit any key to continue...");
   cin.get(ch);
   clearScreen();
}

void flushInput ()
{
   char buff[81];
   if (cin)
      cin.getline(buff,80);    
}

void Warning(char *message)
{
   cerr << message;
}

void Error(char *message)
{
   cerr << message;
   exit(1);
}

void EatWhiteSpace()
{
    char ch;
    do {
      cin.get(ch);
    }
    while(isspace(ch));

    if(ch != EOF)
      cin.putback(ch);
}

bool promptYesNo(char * c)
{
   char ch;
   cout << c << " [y|n]?";
   do {
      cin.get(ch);  
      tolower(ch);
      } while (ch != 'y' && ch != 'n');
   return (ch == 'y');
}

// main.cpp
 
// Conway's Game of Life

#include <iostream>
#include "util.h"
#include "life.h"

using namespace std;

int main() {

  Life configuration;
  instructions(); //Prompts instructions for user
  configuration.initialize();
  configuration.print();

  cout << "Continue viewing new generations? " << endl;

  char user_says_yes = 'y';
  while(user_says_yes == 'y') {

    configuration.update();
    configuration.print();

    cout << "Continue viewing new generations? " << endl;
    cin>>user_says_yes;
  }

}

main=

[edeloss2@pegasus lab1a]$ make
cxx -c -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall main.cpp
cxx: Error: main.cpp, line 14: identifier "instructions" is undefined
  instructions();
--^
cxx: Info: 1 error detected in the compilation of "main.cpp".
make: *** [main.o] Error 1
[edeloss2@pegasus lab1a]$ make veryclean
rm -f *.o
rm -f core
rm -f  main
[edeloss2@pegasus lab1a]$ make
cxx -c -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall main.cpp
cxx: Error: life.h, line 9: invalid combination of type specifiers
typedef int bool;
------------^
cxx: Error: life.h, line 10: expected an identifier
const bool false=0;
-----------^
cxx: Error: life.h, line 11: expected an identifier
const bool true=1;
-----------^
cxx: Error: main.cpp, line 9: name must be a namespace name
using namespace std;
----------------^
cxx: Error: main.cpp, line 14: identifier "instructions" is undefined
  instructions();
--^
cxx: Info: 5 errors detected in the compilation of "main.cpp".
make: *** [main.o] Error 1

???????????????????????????????????????
0
 
avizitCommented:
1. in life.h    you have

void instruction(){}

 you are calling "instructions()" in main /*** notice the extra 's' ****/

void instructions(){};

0
 
Sys_ProgConnect With a Mentor Commented:
for(j=col-1; j<=col+1; J++)

should be

for(j=col-1; j<=col+1; j++)


switch(neighbor_count(row, col) {
should be
switch(neighbor_count(row, col)) {



new_grid[row][col]=grid[ro][col];
should be
new_grid[row][col]=grid[row][col];



DEclarations for instructions; and instructions; nt provided

Amit
0
 
edelossantosAuthor Commented:
okay....this is what I need and I need your help.  

I have tried all code changes and I an still stuck....refer to this url http://www.cs.csubak.edu/~donna/cs223/Text/1.cpp.txt

This is the code that I need help retrofitting:

I am given makefile, util.h, util.cpp.  I need to write life.h, life.cpp, main.cpp

# Makefile:
#        It uses the C++ Compiler with all warnings and
#        full debugging; will create a single executable called 'main'
# ---------------------------------------------------------------
# the compiler
CPP = cxx
# compiler flags
CFLAGS = -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall
# linker flags to link in the libraries libm.a and libtask.a
LFLAGS = -lm -ltask
#
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 life.o util.o

HFILES=            life.h  util.h

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

main.o:            main.cpp life.h util.h
life.o:            life.cpp life.h util.h
util.o:            util.cpp util.h

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


/* Filename: util.h
   Purpose: header file for VT100 screen functions and useful I/O utils
   Note:    a VT100 screen is 24 rows and 80 columns in standard mode */

#ifndef __USE_STD_IOSTREAM
#define __USE_STD_IOSTREAM
#endif

#ifndef UTIL_H  
#define UTIL_H
#include <iostream>
#include <stdlib.h>
#include <time.h>

using namespace std;

/* type bool and  false & true are already defined in dUNIX C++
typedef int bool;
const bool false = 0;  
const bool true = 1;  */

/* this is also in /usr/include/stddef.h which is used in <stdlib.h> */
#define NULL 0L

/* some useful definitions for flag and screen operations */
#define STDSCREEN 80        
#define DOWN 0                        
#define UP   1
#define END   0
#define START 1
#define FAIL    0
#define SUCCESS 1
#define MISS -1
#define HIT   1

/* some useful error codes */
enum Error_code { success, fail, range_error, underflow, overflow, fatal,
                  not_present, duplicate_error, entry_inserted, entry_found,
                  internal_error };

/* screen functions */
void clearScreen ();                   // clears all rows of the screen
void clearTop();                       // clears top row 0 only
void clearBelowTop();                 // clears row 1 down on a vt100 screen
void goTop();                          // moves cursor to the top row 0  
void topLine(const char * text = " "  );   // displays text at row 0
void bottomLine (char * text = " "); // displays text at row 23, column 10

/* I/O functions */
void hitAnyKey ();                   // "Hit any key to continue..." prompt
void flushInput ();                    // reads 80 chars from stdin
void Warning(char *);                  /* writes message to stderr          */
void Error(char *);                    /* writes message to stderr & exits  */
bool promptYesNo(char * prompt="");    /* prompts user to enter yes no */
void EatWhiteSpace(void);              /* discards white space input        */
#endif

/* filename: util.cpp
   Purpose: I/O and VT100 screen manipulation utility functions */

#include "util.h"
#include <ctype.h>
 
/* --------- SCREEN HANDLING FUNCTIONS -
   vertical position goes from 0 - 23
   horizontal position goes from 0 - 79 */

void clearScreen (void)
// Clear everything on screen
{
  cout << "\033[2J";           /* Clear the entire screen. */
  cout << "\033[;f";          /* Move cursor to upper left corner */
}

void clearTop()
// Goto Top-Left corner; Clear to end of line
  {cout << "\033[0;0f" << "\033[0K";}

void clearBelowTop()
// Clear everything except top row
  {cout << "\033[1;0f" << "\033[1B" << "\033[J";}

void goTop ()
// to to the Top-Left corner;
  {cout << "\033[0;0f";}

void topLine(const char str[])
// Goto top-left corner; clear to end of line; print str
  {cout << "\033[0;0f" << "\033[0K" << str;}

void bottomLine (char * str)
  // goto line 23 ; clear line 23; write text
  {cout << "\033[23;0Hf" << "\033[2K" << str;}

/* ----------------  I/O FUNCTIONS */

/* Precondition: the input buffer is empty */
void hitAnyKey ()
{
   char ch;
   bottomLine ("Hit any key to continue...");
   cin.get(ch);
   clearScreen();
}

void flushInput ()
// flush input buffer
{
   char buff[81];
   if (cin)
      cin.getline(buff,80);   // flush the input buffer of 80 characters
}

void Warning(char *message)
{
   cerr << message;
}

void Error(char *message)
{
   cerr << message;
   exit(1);
}

void EatWhiteSpace()
/* discard leading white space */
{
    char ch;
    do {
      cin.get(ch);
    }
    while(isspace(ch));

    if(ch != EOF)
      cin.putback(ch);
}

bool promptYesNo(char * c)
{
   char ch;
   cout << c << " [y|n]?";
   do {
      cin.get(ch);  
      tolower(ch);
      } while (ch != 'y' && ch != 'n');
   return (ch == 'y');
}

// life.h
     
static const int maxrow = 20, maxcol = 60;  

class Life {

public:
   void initialize();
   void initializeRandom();
   void print();
   void update();
   void instructions();

private:
   int grid[maxrow+2][maxcol+2];  
   int neighbor_count(int row, int col);
};

// life.cpp
     
#include "util.h"
#include "life.h"

void Life::initialize()
{
   int row, col;
   for (row = 0; row <= maxrow+1; row++)
      for (col = 0; col <= maxcol+1; col++)
         grid[row][col] = 0;
   
   cout << "\nList coordinate pair for living cells (e.g. 4 5)"
        << " or -1 -1 to end:" << endl;
   cin >> row >> col;

   while (row != -1 || col != -1) {
      if (row >= 1 && row <= maxrow)
         if (col >= 1 && col <= maxcol)
            grid[row][col] = 1;
         else
            cout << "Column " << col << " is out of range." << endl;
      else
         cout << "Row " << row << " is out of range." << endl;
      cin >> row >> col;
   }
}

int Life::neighbor_count(int row, int col)
/*
Pre:  The Life object contains a configuration, and the coordinates
      row and col define a cell inside its hedge.
Post: The number of living neighbors of the specified cell is returned.
*/

{
   int i, j;
   int count = 0;
   for (i = row - 1; i <= row + 1; i++)
      for (j = col - 1; j <= col + 1; j++)
         count += grid[i][j];  //  Increase the count if neighbor is alive.
   count -= grid[row][col]; //  Reduce count, since cell is not its own neighbor.
   return count;
}

void Life::update()
/*
Pre:  The Life object contains a configuration.
Post: The Life object contains the next generation of configuration.
*/

{
   int row, col;
   int new_grid[maxrow + 2][maxcol + 2];

   for (row = 1; row <= maxrow; row++)
      for (col = 1; col <= maxcol; col++)
         switch (neighbor_count(row, col)) {
         case 2:
            new_grid[row][col] = grid[row][col];  //  Status stays the same.
            break;
         case 3:
            new_grid[row][col] = 1;                //  Cell is now alive.
            break;
         default:
            new_grid[row][col] = 0;                //  Cell is now dead.
         }

   for (row = 1; row <= maxrow; row++)
      for (col = 1; col <= maxcol; col++)
         grid[row][col] = new_grid[row][col];
}


void Life::print()
/*
Pre:  The Life object contains a configuration.
Post: The configuration is written for the user.
*/

{
   int row, col;
   clearScreen();
   cout << "The current Life configuration is:" <<endl;
   for (row = 1; row <= maxrow; row++) {
      for (col = 1; col <= maxcol; col++)
         if (grid[row][col] == 1) cout << '*';
         else cout << ' ';
      cout << endl;
   }
   cout << endl;
}


void Life::instructions()
/*
Pre:  None.
Post: Instructions for using the Life program have been printed.
*/

{
   clearScreen();
   cout << "Welcome to Conway's game of Life." << endl;
   cout << "The grid contains "
        << maxrow << " by " << maxcol;
   cout << " cells, each occupied by an organism or not." << endl;
   cout << "The occupied cells change from generation to generation" << endl;
   cout << "according to the number of neighboring cells which are alive."
        << endl;
}

/*  filename: main.cpp
    project: Conway's Game of Life */

#include "util.h"
#include "life.h"

int main()  //  Program to play Conway's game of Life.
/*
Pre:  The user supplies an initial game of living cells.
Post: The program prints a sequence of pictures showing the changes in
      the game of living cells according to the rules for
      the game of Life.
Uses: The class Life and its methods initialize(), print(), and update().
      The functions  instructions(),  and utility functions.  */

{
   Life game;               -> Life configuration;
   game.instructions(); -> configuration.instructions();
   game.initialize();      -> configuration.initialize
   game.print();           ->configuration.print(); cout << "Continue viewing new generations? " << endl;
   while ( promptYesNo("Continue?")) {
      game.update();     ->configuration.update();
      game.print();        ->configuration.print(); cout << "Continue viewing new generations? " << endl;
  }
}

Please advise.  Del


0
 
avizitCommented:
the program you have just now pasted , seems to work ..so what do you have to do exactly ?
0
 
edelossantosAuthor Commented:
I would like to change the function names of the main.cpp.  Del
0
 
edelossantosAuthor Commented:
I could use some ideas and or hints.  Please advise.  Del
0
 
avizitCommented:
I am not sure what you want to do still ..

but if yuo want to do what you pointed by "->" in your code then you can just change main.cpp to

//////////////////MAIN.CPP ////////////////////
#include "util.h"
#include "life.h"

int main()  {
   Life configuration;
   configuration.instructions();
   configuration.initialize()
   
   char continue_flag = 'n' ;
   cout << "Viewing new generations? " << endl;
   cin>>continue_flag;
   while (  (contiue_flag == 'y' ) ||  (continue_flag =='Y')  ) {
             configuration.update();
             cout << "Continue viewing new generations? " << endl;
             cin>>continue_flag;
   }
}

+++++++++++++++++
but *shrugs* i am still unsure why you want to do that
0
 
edelossantosAuthor Commented:
The code you pasted was given by the instructor, and I am trying to implement some of the codes given in the book and the url examples.  Del
0
 
avizitCommented:
okay , so what are the results of your compilation after you have done the corrections i suggested in my last response to YOUR code and not the code from the url

0
 
edelossantosAuthor Commented:
in makefile I am missing seperator

# Makefile:
#        It uses the C++ Compiler with all warnings and
#        full debugging; will create a single executable called 'main'
# ---------------------------------------------------------------
# the compiler
CPP = cxx
# compiler flags
CFLAGS = -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall
# linker flags to link in the libraries libm.a and libtask.a
LFLAGS = -lm -ltask
#
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 life.o util.o

HFILES=          life.h  util.h

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

main.o:          main.cpp life.h util.h
life.o:          life.cpp life.h util.h
util.o:          util.cpp util.h

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

edeloss2@pegasus proto]$ make veryclean
akefile:24: *** missing separator.  Stop.
edeloss2@pegasus proto]$




0
 
avizitCommented:
okay in makefile when you miss seprators its generally the case that you have put spaces instead of tabs.


in lines

          ${CPP} ${CFLAGS} ${LFLAGS} $(OFILES) -o $@
        ${RM} *.o
        ${RM} core
        ${RM}  main

put a tab in front of the lines instead of 8 spaces etc

so should be
<TAB>${CPP} ${CFLAGS} ${LFLAGS} $(OFILES) -o $@

etc etc etc

where <TAB> is the tab key or character ,



0
 
edelossantosAuthor Commented:
PART III.
Answer these questions in the body of the same email:

What is a linker and what tasks does it perform? (try 'man ld')

The ld command invokes the DIGITAL UNIX link editor ("linker") which links
extended COFF object files.

Explain each line of the following output from the make utility.
cxx -c -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall  life.cpp

life.cpp compiled.

cxx -c -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall  util.cpp

util.cpp compile.

cxx -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall  -lm -ltask main.o life.o util.o
 -o main

compilation unit object files.

ld (prelink):

load option.


util.o compressed: x: multiply defined

?????????????????

Am I correct on the definitions, the last one I am clueless.

0
 
edelossantosAuthor Commented:
# Makefile:
#        It uses the C++ Compiler with all warnings and
#        full debugging; will create a single executable called 'main'
# ---------------------------------------------------------------
# the compiler
CPP = cxx
# compiler flags
CFLAGS = -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall
# linker flags to link in the libraries libm.a and libtask.a
LFLAGS = -lm -ltask
#
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:
<TAB>${CPP} -c ${CFLAGS} $<

OFILES=          main.o life.o util.o

HFILES=          life.h  util.h

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

main.o:          main.cpp life.h util.h
life.o:          life.cpp life.h util.h
util.o:          util.cpp util.h

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







                               [ Wrote 48 lines ]

[edeloss2@pegasus proto]$ make veryclean
makefile:24: *** missing separator.  Stop.
[edeloss2@pegasus proto]$

???
0
 
edelossantosAuthor Commented:
anyone outhere???
0
 
edelossantosAuthor Commented:
OOPS!!!
0
 
edelossantosAuthor Commented:
makefile fixed, glitch in main.cpp

//main.cpp

#include<iostream>

using namespace std;

#include "util.h"
#include "life.h"

int main()  {
   Life configuration;
   configuration.instructions();
   configuration.initialize()
   
   char continue_flag = 'n' ;
   cout << "Viewing new generations? " << endl;
   cin>>continue_flag;
   while (  (contiue_flag == 'y' ) ||  (continue_flag =='Y')  ) {
             configuration.update();
             cout << "Continue viewing new generations? " << endl;
             cin>>continue_flag;
   }
}

make =

[edeloss2@pegasus proto]$ make
cxx -c -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall  main.cpp
cxx: Error: main.cpp, line 5: name must be a namespace name
using namespace std;
----------------^
cxx: Error: main.cpp, line 15: expected a ";"
   char continue_flag = 'n' ;
---^
cxx: Error: main.cpp, line 17: identifier "continue_flag" is undefined
   cin>>continue_flag;
--------^
cxx: Error: main.cpp, line 18: identifier "contiue_flag" is undefined
   while (  (contiue_flag == 'y' ) ||  (continue_flag =='Y')  ) {
-------------^
cxx: Info: 4 errors detected in the compilation of "main.cpp".
make: *** [main.o] Error 1
[edeloss2@pegasus proto]$ make veryclean
rm -f *.o
rm -f core
rm -f  main
[edeloss2@pegasus proto]$ make
cxx -c -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall  main.cpp
cxx: Error: main.cpp, line 5: name must be a namespace name
using namespace std;
----------------^
cxx: Error: main.cpp, line 15: expected a ";"
   char continue_flag = 'n' ;
---^
cxx: Error: main.cpp, line 17: identifier "continue_flag" is undefined
   cin>>continue_flag;
--------^
cxx: Error: main.cpp, line 18: identifier "contiue_flag" is undefined
   while (  (contiue_flag == 'y' ) ||  (continue_flag =='Y')  ) {
-------------^
cxx: Info: 4 errors detected in the compilation of "main.cpp".
make: *** [main.o] Error 1

0
 
avizitCommented:
the line

configuration.initialize()


should have a semi colon i.e ';'    follwoing it

i am snot sure whats wrong with

using namespace std;    

try to comment out that line and see
0
 
edelossantosAuthor Commented:
//main.cpp

#include<iostream>

//using namespace std;

#include "util.h"
#include "life.h"

int main()  {
   Life configuration;
   configuration.instructions();
   configuration.initialize();
   
   char continue_flag = 'n' ;
   cout << "Viewing new generations? " << endl;
   cin>>continue_flag;
   while (  (contiue_flag == 'y' ) ||  (continue_flag =='Y')  ) {
             configuration.update();
             cout << "Continue viewing new generations? " << endl;
             cin>>continue_flag;
   }
}

[edeloss2@pegasus proto]$ make veryclean
rm -f *.o
rm -f core
rm -f  main
[edeloss2@pegasus proto]$ make
cxx -c -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall  main.cpp
cxx: Error: main.cpp, line 18: identifier "contiue_flag" is undefined
   while (  (contiue_flag == 'y' ) ||  (continue_flag =='Y')  ) {
-------------^
cxx: Info: 1 error detected in the compilation of "main.cpp".
make: *** [main.o] Error 1
[edeloss2@pegasus proto]$ main
bash: main: command not found
0
 
avizitCommented:
you have written

char continue_flag = 'n' ;


and

while (  (contiue_flag == 'y' ) ||  (continue_flag =='Y')  )


seeyou have a typo here ... check the spelling of continue_flag

0
 
edelossantosAuthor Commented:
//util.cpp

#include <iostream>
using namespace std;

#include "util.h"

void clearScreen (void)
 
{
  cout << "\033[2J";          
  cout << "\033[;f";          
}

void clearTop()
{
  cout << "\033[0;0f" << "\033[0K";
}

void clearBelowTop()
{
  cout << "\033[1;0f" << "\033[1B" << "\033[J";
}

void goTop ()
{
  cout << "\033[0;0f";
}

void topLine(const char str[])
{
  cout << "\033[0;0f" << "\033[0K" << str;
}

void bottomLine (char * str)
{
  cout << "\033[23;0Hf" << "\033[2K" << str;
}

void hitAnyKey ()
{
   char ch;
   bottomLine ("Hit any key to continue...");
   cin.get(ch);
   clearScreen();
}

void flushInput ()
{
   char buff[81];
   if (cin)
      cin.getline(buff,80);    
}

void Warning(char *message)
{
   cerr << message;
}

void Error(char *message)
{
   cerr << message;
   exit(1);
}

void EatWhiteSpace()
{
    char ch;
    do {
      cin.get(ch);
    }
    while(isspace(ch));

    if(ch != EOF)
      cin.putback(ch);
}

bool promptYesNo(char * c)
{
   char ch;
   cout << c << " [y|n]?";
   do {
      cin.get(ch);  
      tolower(ch);
      } while (ch != 'y' && ch != 'n');
   return (ch == 'y');
}

make =

[edeloss2@pegasus proto]$ make veryclean
rm -f *.o
rm -f core
rm -f  main
[edeloss2@pegasus proto]$ make
cxx -c -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall  main.cpp
cxx -c -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall  life.cpp
cxx -c -L/usr/lib/cmplrs/cxx -DPOSIX_4D9 -w0 -gall  util.cpp
cxx: Error: util.cpp, line 5: name must be a namespace name
using namespace std;
----------------^
cxx: Error: util.cpp, line 57: identifier "exit" is undefined
   exit(1);
---^
cxx: Error: util.cpp, line 66: identifier "isspace" is undefine
    while(isspace(ch));
----------^
cxx: Error: util.cpp, line 78: identifier "tolower" is undefine
      tolower(ch);
------^
cxx: Info: 4 errors detected in the compilation of "util.cpp".
make: *** [util.o] Error 1



0
 
edelossantosAuthor Commented:
are you still outhere avizit ?
0
 
avizitCommented:
try commenting out the

using namespace std;

and  add
#include <cstdlib>

in util.cpp
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.