vijayan121 1,152 Posting Virtuoso

if you are interested in only an approximate value, you could use a type like double for computing the result. for example, a long double can hold very large values, but precision is limited (on my compiler, the mantissa is accurate upto 15 decimal digits).

#include <limits>
#include <iostream>
#include <iomanip>
using namespace std;

inline long double factorial( unsigned int n )
{
   long double result = 1.0 ;
   while( n>1 ) result *= n-- ;
   return result ;
}

int main()
{
  cout << "unsigned int-\t" << numeric_limits< unsigned int >::max() << '\t'
       << numeric_limits< unsigned int >::digits10 << " decimal digits\n" ;
  cout << "long double-\t" << numeric_limits< long double >::max() << '\t'
       << numeric_limits< long double >::digits10 << " decimal digits\n" ; ;

  cout << fixed << setprecision(0) << "53! ~= " << factorial(53) << '\n' ;
}
/**
>g++ -Wall -std=c++98 num_limits.cpp && ./a.out
unsigned int-   4294967295      9 decimal digits
long double-    1.18973e+4932   15 decimal digits
53! ~= 4274883284060023952295713899453537359909467862005827442747675726839808
*/

for accurate results, you could use a library eg. https://sourceforge.net/projects/cpp-bigint/

SpS commented: Nicely Presented +3
vijayan121 1,152 Posting Virtuoso

> I know the if statement would be a better choice but I must you use the switch for an assignment
would this make your teacher happy?

enum { LESS_THAN_10000, NOT_LESS_THAN_10000 };
int to_be_used_in_switch = sales < 100000.0 ? 
                       LESS_THAN_10000 : NOT_LESS_THAN_10000 ;
switch( to_be_used_in_switch )
{
       case LESS_THAN_10000:
            /* ... */ break ;
       case NOT_LESS_THAN_10000:
            /* ... */ break ;
       default:
            assert(false) ;
 }
Hamrick commented: ooh, good idea! +2
vijayan121 1,152 Posting Virtuoso

an alternative is to use the ctype<> facet. the advantages are a. also works with c++ strings b. locales other than the default locale are supported (behaviour is unaffected by the LC_CTYPE category of the current c locale). 3. will not fail if a wide-character code encountered does not correspond to a valid character.

#include <locale>
#include <iostream>
#include <string>
#include <sstream>
using namespace std ;

wstring widen( const string& str )
{
    wostringstream wstm ;
    const ctype<wchar_t>& ctfacet = 
                        use_facet< ctype<wchar_t> >( wstm.getloc() ) ;
    for( size_t i=0 ; i<str.size() ; ++i ) 
              wstm << ctfacet.widen( str[i] ) ;
    return wstm.str() ;
}

string narrow( const wstring& str )
{
    ostringstream stm ;
    const ctype<char>& ctfacet = 
                         use_facet< ctype<char> >( stm.getloc() ) ;
    for( size_t i=0 ; i<str.size() ; ++i ) 
                  stm << ctfacet.narrow( str[i], 0 ) ;
    return stm.str() ;
}

int main()
{
  {
    const char* cstr = "abcdefghijkl" ;
    const wchar_t* wcstr = widen(cstr).c_str() ;
    wcout << wcstr << L'\n' ;
  }
  {  
    const wchar_t* wcstr = L"mnopqrstuvwx" ;
    const char* cstr = narrow(wcstr).c_str() ;
    cout << cstr << '\n' ;
  } 
}
WolfPack commented: I didn't know this. Thank you. +7
vijayan121 1,152 Posting Virtuoso

> i did what you suggested and i got::....
you have not defined node::node_pool.
see line 23 of the earlier post boost::pool<> node::node_pool( sizeof(node) ) ;

n.aggel commented: excellent poster! +1
vijayan121 1,152 Posting Virtuoso
struct singleton
{
  // return a reference, not a pointer. the problem with returning
  // a pointer is that a caller might be tempted to call delete on it
  // returning an auto_ptr<> to a singleton is ruled out; 
  // it's (or it's copy's) destructor *will* call delete on the object.
  static singleton& get_the_only_object() ;

  /* other operations */
           
  private :
    
    // no accessible constructor; only way to get the singleton
    // is through the public *static* method 
    singleton() { /* ... */ }
    
    // copy constructor; there is only one object, copy of it should not
    // be created. do not define this!
    singleton( const singleton& ) ;

    // only one object; assignment is always a trivial self-assignment
    // do not define this!
    void operator= ( const singleton& ) ;

    /* other private stuff */
};

// this simple idea was first presented by scott myers
// see 'more effective c++', item 26
singleton& singleton::get_the_only_object()
{
  // created the first time flow of control reaches this point
  static singleton the_only_one ;
  // destroyed after main returns 
  return the_only_one ;
}

int main()
{
  // a user gets (a reference to) the singleton object this way
  singleton& object = singleton::get_the_only_object() ;
  // object.do_something() ;
}

this works fine in many cases. however, as andrei alexandrescu points out in his book 'modern c++ design', "The singleton design pattern is unique in that ... it's description is simple, but it's implementation is complicated". and then goes on to discuss singleton implementation issues in some 25 pages or so.

vijayan121 1,152 Posting Virtuoso

you do not have to close and then reopen the file; inData.clear() ; inData.seekg(0) ; is more efficient.
> I need the number of lines before I can correctly do the other stuff.
you do not; use a vector instead of a c-style array:

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std ;

int main()
{
   ifstream file( __FILE__ ) ;
   string line ;
   vector<string> lines ;
   while( getline( file, line ) ) lines.push_back( line ) ;
   cout << "#lines: " << lines.size() << '\n' ;
}
SpS commented: Good ~SpS +3
vijayan121 1,152 Posting Virtuoso

...compile and run the program on a more current compiler

runs without any problems on microsoft vc++ 8.0 and gcc 3.4.x (need to change headers iostream.h => iostream etc.)

Also I would value advice on which replacement compiler I should acquire. I would want an IDE and the machine computer interface board and real time limits me to using dos.

if you have to run under dos, this is reported to be a workable solution: http://www.delorie.com/djgpp/doc/ug/intro/what-is-djgpp.html & http://www.delorie.com/djgpp/v2faq/ it supports 32 bit addressing; so array sizes are not an issue if you have sufficient ram. see: http://www.delorie.com/djgpp/doc/ug/basics/32bit.html there is an ide for gjgpp: ttp://www.rhide.com/ djgpp is particularly popular among game programmers.

note: Salem's idea (sending a large array in smaller chunks of <64k) would be a simple and elegant solution; you should not rule it out without investigating the possibility.

Salem commented: Good idea - DJGPP +9
vijayan121 1,152 Posting Virtuoso
printf((char *)&num);

is clearly an error; you are casting a double* to a char* (which is incorrect). unpleasant consequences would be the norm if you do such things. in C, to print out a double value, use

printf( "%f", num ) ;

instead.
atof is to be shunned; it has many problems. you would be much better off (and less likely to make errors) if you use C++ facilities where they are available. eg.

#include <string>
#include <iostream>
#include <sstream>
using namespace std ;

/*void*/ int main()
{
  double num = 310.589 ;
  /* char buffer [10]; */ string buffer ;
  /* sprintf(buffer,"%f",num); */ 
 { ostringstream stm ; stm << num ; buffer = stm.str() ; }
  // buffer[7] = *NULL;
  /*
  printf("using &num=\n");
  printf((char *)&num);
  printf("\nbuffer=\n");
  printf(buffer);
  printf("\nfragment of buffer=\n");
  printf((char *)&buffer[3]);
  */
  cout << "using &num= " << &num << "\nbuffer= " << buffer
       <<  "\nfragment of buffer= " << &( buffer.c_str()[3] ) << '\n' ;
  /* scanf("%s",buffer); */ cin >> buffer ;
  /* num=atof(buffer); */
  {
    istringstream stm(buffer) ;
    stm >> num ;
    if( !stm ) cerr << "conversion failed\n" ;
  }
  num/=2;
  /* printf("\n%lf",num); */ cout << num << '\n' ;
  /* _getch(); */ char ch ; cin >> ch ;
}

if you are preparing yourself for c++0x (you really should; final draft should be out in a few months), you could write

#include <string>
#include <iostream>
#include <sstream>
#include <boost/lexical_cast.hpp>
using namespace std ;
using namespace boost ;

int …
Salem commented: Good stuff +9
vijayan121 1,152 Posting Virtuoso

dynamic scoping is almost never used these days. with dynamic scoping, a variable reference is bound to the most recent instance of that variable on the call stack. for example:

#ifdef this_should_not_compile
void b() ; void c() ;
void a()
{
  int x = 24 ;
  int y = 32 ;
  int z = 0 ;
  b() ;
  assert( z == 132 ) ;
}

void b()
{
  int x = 100 ;
  c() ;
}

void c()
{
   z = x + y ; // would mean a()::z = b()::x + a()::y   
}

#endif // this_should_not_compile

// most C/C++ implementations use "context parameters" to simulate this
// for example, these are some Xlib functions:
//  
// int XDrawLine( Display* display, Drawable d, GC gc,
//                int x1, int y1, int x2, int y2 ) ;
// int XDrawArc( Display* display, Drawable d, GC gc,
//               unsigned int width, unsigned int height,
//               int angle1, int angle2 ) ;
//
// the parameters Display*, Drawable ang GC are the "context parameters"
// 
// with dynamic scoping, we could simply write
//
// int XDrawLine( int x1, int y1, int x2, int y2 ) ;
// int XDrawArc( unsigned int width, unsigned int height,
//               int angle1, int angle2 ) ;
//
// and the functions could pick up the caller's Display* display, 
// Drawable d, and GC gc from the stack frame

there are reasons why dynamic scoping has mostly disappeared from programming languages.
1. though it makes …

Salem commented: Ah yes, closures - a lot easier in some other languages. +9
vijayan121 1,152 Posting Virtuoso

the total store of c++ functions is fixed. these are the functions which were written when the code was compiled; there is simply no way to create new functions at run time. what differentiates function objects from functions is that they are objects (variables). in principle we can do everything with them that we can do with any other kind of variable. among other things, thay can hold state, they can be modified at run time and they can be created at run time. simply put, function objects give us a means to bundle a function call with implicit arguments to pass to that function. this allows us to build up complicated expressions using surprisingly simple syntax.

perhaps an example would help. we want to sort a sequence of integers; the sort criteria is a single digit of the integer at a position N (digit 0 being the least significant one). the value of N is known only at run time.
here is a version using c library qsort which requires a pointer to a comparison function (we avoid global variables for all the usual reasons - they encourage tight coupling, are a recipe for disaster in the presence of concurrency etc.):

#include <cstdlib>
#include <vector>
#include <iostream>
#include <boost/random.hpp>
#include <iterator>
#include <cassert>
using namespace std ;
using namespace boost ;

int compare_digit( int first, int second, int digit )
{
  int div = 1 ;
  for( int i=0 ; i<digit ; ++i ) div *= …
shouvik.d commented: You are the best to explain...Cheers to you +1
vijayan121 1,152 Posting Virtuoso
#include <fstream>
#include <string>
#include <vector>
#include <cassert>
using namespace std ;

int main()
{
  const char DELIM = '>' ;
  const char* const file_name = "whatever" ;
  ifstream file( file_name ) ; assert(file) ;
  vector<string> names, sequences ;
  string line ; 

  // skip lines till we get one starting with DELIM
  while( getline(file, line) ) 
    if( !line.empty() && line[0]==DELIM ) break ;

  names.push_back( line.substr(1) ) ;
  string charseq ;
  while( getline(file, line) )
  {
    if( !line.empty() && line[0] == DELIM )
    {
      sequences.push_back(charseq) ;
      charseq.clear() ;
      names.push_back( line.substr(1) ) ;
    }
    else
     charseq += line + '\n' ;
  }
  sequences.push_back(charseq) ;
}
iamthwee commented: short n sweet +11
vijayan121 1,152 Posting Virtuoso
template <typename T> void template_function( T arg ) ;

template <typename T>
void function( void (*func)(T) )
 { /* ... */ }

// this is better, would also accept compatible functions 
// and function objects
template <typename FN>
void better_function( FN arg )
 { /* ... */ }
vijayan121 1,152 Posting Virtuoso

btw, I've already seen this: http://code.google.com/p/google-sparsehash/
was wondering if there is more like this ? any other containers' implementation.. ?

documentation for dense/sparse hash/map/table is available at
http://google-sparsehash.googlecode.com/svn/trunk/doc/index.html
dense_hash/map trades memory for performance, sparse versions are very memory efficient, but slow. the performance is good, but the difference between O(N logN) and O(N) [ log N ] should be about 20 to 21 times for our data set. the gcc implementation is really a first beta; i think the focus was on getting out a working version, not performance.

you may also find this link interesting
http://code.google.com/p/google-perftools/wiki/GooglePerformanceTools
TCMalloc is really fast.

both are truly free (under the nonviral BSD license); you could use it in anyway you want without restrictions.

more code is available at http://code.google.com/
i've not tried any of the others.

~s.o.s~ commented: Nice +22
vijayan121 1,152 Posting Virtuoso
if( std::find( alist.begin(), alist.end(), x ) != alist.end() )
{ /* do this */ }
vijayan121 1,152 Posting Virtuoso

It's just simple maths

void process ( int a, int b ) {
  char var[10];
  process( 0, 0 );
}

You have a char array, so that's 10 bytes.
Two integers - say 4 bytes each (total 8).
Each call has a fixed overhead of several bytes (say saving the return address of the call), another 8.

So that's 26 bytes in this example.
26 * 22460 = 583960...

we need to also take into acount
a. padding that would be added to align data (eg. in the above example, 2 bytes for the char array in a 32 bit architecture).
b. many compilers would also insert canaries on the stack to enable stack smashing protection. microsoft c++ 8, icc 9, gcc on FreeBSD, NetBsd, OpenBSD and SystemX all implement canaries by default. these canaries would be there in every stack frame (see http://en.wikipedia.org/wiki/Stack-smashing_protection#Implementations )

~s.o.s~ commented: nice +20
Rashakil Fol commented: hi +6
vijayan121 1,152 Posting Virtuoso
WolfPack commented: Nice links +8
vijayan121 1,152 Posting Virtuoso

...NetBeans...That's for Java. An entirely different programming language.

see http://www.netbeans.org/products/cplusplus/
it is lighter on resources than eclipse+cdt, and would be a good option for a c++ IDE, particularly on a unix/linux platform.

John A commented: Ah, thanks. +13
vijayan121 1,152 Posting Virtuoso

Why this is legal?
(****bar)() ;

void bar() { /* ...  */ }

int main()
{
  void (*pfn)() = bar ; // ok, bar is treated as &bar
  void (&rfn)() = *pfn ; // ok, *pfn is a reference to the function
  pfn = rfn ; // ok, equivalent to pfn = &rfn ;
  pfn = *bar ; // ok, equivalent to pfn = &*&bar ;
  pfn = **bar ; // ok, equivalent to pfn = &*&*&bar ;
  pfn = ***bar ; // ok, equivalent to pfn = &*&*&*&bar ;
  (*pfn)() ; // ok, call bar
  (****bar)() ; // ok, equivalent to (*pfn)() ;
}
~s.o.s~ commented: Nice. +19
vijayan121 1,152 Posting Virtuoso

get to the command line terminal, cd to the directory and type
copy /A *.txt all.txt
you will get one big text file. i'm not sure about microsoft (or any other) word, but it should be possible to convert a text file to a word processing document.

Salem commented: Gotta love 1-line simplicity +6
vijayan121 1,152 Posting Virtuoso

... I can not take tap position and calculate my new bit. of course another poblem is shifting but ...

ok, jerry. here is an implementation in C++; i have written it in C++ because a. i find it easier to explain bit-wise operations in code rather than in words. b. writing it in C would be me doing your homework. my suggestion is: ignore the C++ syntax, focus on the logic instead. and if you can treat this as psuedocode and rewrite it in C, you would have solved the problem yourself.

#include<iostream>
#include <bitset>
#include <string>
#include <set>
#include <iomanip>
using namespace std ;

enum { NBITS = 8 };
typedef bitset<NBITS>  shift_register ;
enum bit { zero=0, one=1 };

// returns the bit shifted out
bit shift( shift_register& value, const shift_register& tap_sequence ) ;

int main()
{
  cout << "shift register value (" << NBITS << " bits[0/1]): " ; 
  string value_string ; cin >> value_string ;
  shift_register value( value_string ) ;
  cout <<   value[0] << '\n' ;

  string tap_string  = "10110010" ; // a good tap sequence for 8 bits 
  //cout << "tap_sequence: (" << NBITS << " bits[0/1]): " ;
  //cin >> tap_string ;
  shift_register tap_sequence( tap_string ) ;

  cout << "value: " << value << "\ttap_sequence: " << tap_sequence << '\n' ;

  set<unsigned long> number_stream ; // numbers generated so far
  int period = 0 ;
  while(true)
  {
     string number_string ;
     static const char* const literal_bit = "01" ;
     
     // get the next …
~s.o.s~ commented: A good concept of help without actually doing the homework. +19
vijayan121 1,152 Posting Virtuoso

Actually, my idea is to run rand (not sure how many times I'll need to), and to then say for each time it returns a number, the program should check that current number with the previous one; if the current number is larger than the previous one, it gets printed to screen, if not, it gets ignored (i.e. nothing happens to it) and rand keeps going. And I'm finding that quite challenging at the moment.

rand() could return a large value (RAND_MAX for instance); your program would then loop infinitely. you will have to do something like
if the value of ( RAND_MAX - largest_so_far ) is less than random_numbers_remaining, start all over again from scratch.

if you are willing to iterate from 0 to RAND_MAX, the problem is much easier to solve.

added later

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std ;

void generate_ascending_rand( int N )
{
  int available = RAND_MAX ;
  int required = N ;

  for( int i=0 ; i<available ; ++i )
    // to choose required out of the remaining (available-i)
    if( ( rand() % (available-i) ) < required ) 
    {
      --required ;
      cout << i << '\n' ;
    }
}

int main()
{
  srand( unsigned( time(0)) ) ;
  generate_ascending_rand(50) ;
}
Thinka commented: Very helpful +3
vijayan121 1,152 Posting Virtuoso

if you are comfortable with c++ (ie. you can do more than write c code using c++ syntax), you would find the spirit recursive descent parser framework (part of the boost libraries) easy to use. internally, it uses template meta-programming techniques; but to use it productively, you just need to be familiar with mainstream c++ (primarily generic programming).

here is an example of parsing a text file:
file key_and_values.txt
------------------------------

phone_numbers = 1234, 5678 : 987,564:0:0
line 2 is a parse error
primes_2_to_19 = 2, 3, 5, 7, 11:13:17:19
primitive_pythagorian_triplet_1 = 8,15 : 7
line = 5 also an error
_12_34 = 1:2, 3:4
_daniweb_thread_numbers = 12345:56789:34567, 78901
primitive_pythagorian_triplet_2 = 9,12 : 15
adds_up_to_12 = -24 : +48 , -12

essentially it contains lines of the form
key = value, value : value.
keys have the same structure as valid c++ identifiers.
values are integers seperated by either a , or a :
white spaces are ignored.

here is a sample program that parses such a file:

#include <boost/spirit/core.hpp>
#include <boost/spirit/actor.hpp>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
using namespace std;
using namespace boost::spirit;

bool parse_it( const char* cstr, string& key, vector<int>& values )
{
    return parse( cstr,
     ( ( ( (alpha_p|'_') >> *(alnum_p|'_') )[ assign_a(key) ] ) >> ( '=' >> 
       ( int_p[ push_back_a( values ) ] >> *(  ( ch_p(',') | ':' ) >> …
MaestroS commented: Thanks for it +1
vijayan121 1,152 Posting Virtuoso

i think the best way would be
a. allocate an array of pixel* , one entry per transmitter.

pixel** ppp = new pixel* [ NUM_TRANSMITTERS ] ;

b. as you read each file, allocate memory for the pixels

ppp[transmitter_number] = new pixel[npixels_in_this_transmitter] ;

c. you could either read the file data directly into the array, or you could create a local variable of type pixel and copy it into the array. do not worry about the overhead of copying the pixel object; it is small (x,y,power) and can be copied using bit-wise semantics (in c++ jargon, has a trivial copy constructor). so the compiler will generate the copy code inline (three or four instructions for your pixel).
d. need a little more information about destroying pixels. do you destroy pixels one by one or is it that when a new file comes in, you destroy all the pixels for that transmitter and create a new set of pixels? and if it is the second case, would the number of pixels change?

thekashyap commented: Rep was due, just forgotten.. :). Thanks. For all posts in this thread +1
vijayan121 1,152 Posting Virtuoso

you do not have to make one. it is available in libraries.
either the boost string algorithms or the boost tokenizer could be used.

here is an example using the boost string algorithms split. as you can notice, c++ libraries are
far more powerful and expressive. in this example, we are splitting on different criteria and placing the
result into different types of containers. and we are using one function: split to do all this.

#include <iostream>
#include <boost/algorithm/string.hpp>
#include <boost/lambda/lambda.hpp>
#include <vector>
#include <list>
#include <deque>
#include <algorithm>
using namespace std;
using namespace boost;
using namespace boost::lambda;

template<typename C> inline void print( const C& cntr )
{ for_each( cntr.begin(), cntr.end(), cout << constant('[') << _1 << "]  " ) ; }

int main()
{
  string str = "ab+*%cde4fg*hijk   lmno%+pqr3stu--vwx yz   "
                       "ab0cde+fgh2ij345klm4nop5qr7st" ;

  vector<string> vec ;
  split( vec, str, is_any_of("+*%-"), token_compress_on ) ; 
  print(vec) ; cout << '\n' ; 

  list<string> lst ;
  split( lst, str, is_from_range('2', '6') ) ; // token_compress_off by default
  print(lst) ; cout << '\n' ; 

  deque<string> deq ;
  split( deq, str, is_space(), token_compress_on ) ; 
  print(deq) ; cout << '\n' ; 
}

and this is the output:
g++ -Wall -std=c++98 -I/usr/local/include split.cpp ; ./a.out
[ab] [cde4fg] [hijk lmno] [pqr3stu] [vwx yz ab0cde] [fgh2ij345klm4nop5qr7st]
[ab+*%cde] [fg*hijk lmno%+pqr] [stu--vwx yz ab0cde+fgh] [ij] [] [] [klm] [nop] [qr7st]
[ab+*%cde4fg*hijk] [lmno%+pqr3stu--vwx] [yz] [ab0cde+fgh2ij345klm4nop5qr7st]


ps: i should qualify my first statement; you do not have to make one; …

StuXYZ commented: Really nice example, thx +3
vijayan121 1,152 Posting Virtuoso

Hi!

How can I read all files in a directory, when I don't know which files are
there?

Sincerely
Jasmina Jeleva!

you could use the boost filesystem library.
it is portable across unix, linux and windows.

here is a sample program which prints the names of all files in a directory.

#include <iostream>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/fstream.hpp>
using namespace boost::filesystem; 
using namespace std;

void show_files( const path & directory, bool recurse_into_subdirs = true )
{
  if( exists( directory ) )
  {
    directory_iterator end ;
    for( directory_iterator iter(directory) ; iter != end ; ++iter )
      if ( is_directory( *iter ) )
      {
        cout << iter->native_directory_string() << " (directory)\n" ;
        if( recurse_into_subdirs ) show_files(*iter) ;
      }
      else 
        cout << iter->native_file_string() << " (file)\n" ;
  }
}

int main()
{
    show_files( "/usr/share/doc/bind9" ) ;
}

on my machine it produced the following output.

g++ -std=c++98 -Wall -I/usr/local/include file_system.cpp /usr/local/lib/libboost_filesystem.a ; ./a.out

/usr/share/doc/bind9/arm (directory)
/usr/share/doc/bind9/arm/Bv9ARM.ch01.html (file)
/usr/share/doc/bind9/arm/Bv9ARM.ch02.html (file)
/usr/share/doc/bind9/arm/Bv9ARM.ch03.html (file)
/usr/share/doc/bind9/arm/Bv9ARM.ch04.html (file)
/usr/share/doc/bind9/arm/Bv9ARM.ch05.html (file)
/usr/share/doc/bind9/arm/Bv9ARM.ch06.html (file)
/usr/share/doc/bind9/arm/Bv9ARM.ch07.html (file)
/usr/share/doc/bind9/arm/Bv9ARM.ch08.html (file)
/usr/share/doc/bind9/arm/Bv9ARM.ch09.html (file)
/usr/share/doc/bind9/arm/Bv9ARM.html (file)
/usr/share/doc/bind9/misc (directory)
/usr/share/doc/bind9/misc/dnssec (file)
/usr/share/doc/bind9/misc/format-options.pl (file)
/usr/share/doc/bind9/misc/ipv6 (file)
/usr/share/doc/bind9/misc/migration (file)
/usr/share/doc/bind9/misc/migration-4to9 (file)
/usr/share/doc/bind9/misc/options (file)
/usr/share/doc/bind9/misc/rfc-compliance (file)
/usr/share/doc/bind9/misc/roadmap (file)
/usr/share/doc/bind9/misc/sdb (file)
/usr/share/doc/bind9/CHANGES (file)
/usr/share/doc/bind9/COPYRIGHT (file)
/usr/share/doc/bind9/FAQ (file)
/usr/share/doc/bind9/README (file)

vijayan121 1,152 Posting Virtuoso

comparing a signed value with an unsigned
value has a logical problem.

int si = -7 ;
unsigned int ui = 68 ;
( si < ui ) ; 
// true if interpreted as si < signed(ui)
// false if interpreted as unsigned(si) < ui

at the very least, the behavoiur is
'implementation dependant'

however, if the signed value is >= 0, and
the unsigned value is less than half of the
possible max value for the type, there
would be no differences between
implementations.

Daniel E commented: Makes sense and helpful +1
vijayan121 1,152 Posting Virtuoso

> You cannot use C to solve this problem.
Of course you can, it just takes an additional library to help you do all the hard stuff.
http://gmplib.org/

Or if you're only interested in a couple of math ops, then you could work out how to do long arithmetic in your own code instead.

#include<stdio.h>

int value_digits( int a, int b, int c ) { return a*100 + b*10 + c ; }
int value_sum_power( int a, int b, int c ) { return a*a*a + b*b*b + c*c*c ; }

int main()
{
  for( int a=0 ; a<10 ; ++a )
      for( int b=0 ; b<10 ; ++b )
          for( int c=0 ; c<10 ; ++c )
          {
            int number = value_digits(a,b,c) ;
            if( number == value_sum_power(a,b,c) )
              printf( "%d\n", number ) ;
          }
  return 0 ;
}
Aia commented: Great job -Aia- +1
vijayan121 1,152 Posting Virtuoso

since we are using std::string, why not

#include <iostream>
#include <string>
using namespace std;
int main()
{
  string str ;  cin >> str ; 
  const string vowels = "aeiouAEIOU" ;
  int n_vowels = 0 ;
  for( string::size_type pos = str.find_first_of(vowels) ; pos != string::npos ;
        pos = str.find_first_of(vowels,pos+1) )  ++n_vowels ;
  cout << "vowels: " << n_vowels  << "\nconsonants: " 
          << str.size()-n_vowels    << '\n' ;
  return 0 ;
}
~s.o.s~ commented: Yes a good approach but too much for a beginner..;) - ~s.o.s~ +15
vijayan121 1,152 Posting Virtuoso

for your specific problem:
1-100 arrays of size 10 with randomly distinct numbers from (0-9)
2-100 arrays of size 50 with randomly distinct numbers from (0-49)
3-100 arrays of size 100 with randomly distinct numbers from (0-99)
4-100 arrays of size 200 with randomly distinct numbers from (0-199)

u could fill an array of size N with values
0, 1, 2, ..., N-2, N-1
and then just do a std::random_shuffle on it.
(after seeding the random number generator)

Salem commented: Excellent suggestion, but probably too advanced to hand in as noob homework +6