gerard4143 371 Nearly a Posting Maven

Or posting in the wrong section?

fahadmunir32 commented: Can u tell where to post this kind of discussion +0
gerard4143 371 Nearly a Posting Maven

C++ is a play on the C programming language increment operator. C++ literally means C language incremented.

What's the purpose of it? Here check the wiki

http://en.wikipedia.org/?title=C%2B%2B

gerard4143 371 Nearly a Posting Maven

Yes, you will searching for the element contained in the array std. If you need to search id in the array std then you could loop through std and check each id.

size_t i = 0;

for (; i < 100; ++i)
{
    if (std[i].id == some_int)
    {
        //do something here
    }
}
gerard4143 371 Nearly a Posting Maven

Well this is how you access an element of std[100] and get its elements.

std[searchid].id
std[searchid].name
std[searchid].fatherName
std[searchid].motherName
centenond commented: (y) +0
gerard4143 371 Nearly a Posting Maven

If you insists on breaking out of the loop immediately then you should use break.

Something like this...

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    int employeeNumber = 0;

    while( true )
    {
        cout << "\nEmplyee Number: ";
        cin >> employeeNumber;
        cout << endl;

        if ( employeeNumber == 0 ) break;

        while( true )
        {
            cout << "Inner loop\n";
            //do something here
        }
    }
    cout << "Done" << endl;
    return 0;
}
gerard4143 371 Nearly a Posting Maven

If you want to save yourself some frustration then don't include this in your header file

using namespace std;

Header files shouldn't expose anything in a namespace.

gerard4143 371 Nearly a Posting Maven

This forums provides help to users who have specific questions. It isn't a free programming advice column.

gerard4143 371 Nearly a Posting Maven

Could you elaborate on your question?

gerard4143 371 Nearly a Posting Maven

I would have to say that you need a flagging system which marks a integer element when its been counted.

Are you sure this is C?

for(int i = 0; i < 10; i++)
{
...
}
gerard4143 371 Nearly a Posting Maven

Looking at your code I find that you have to make a decision. Do you want to calculate the average once and store the value in the structure Student or do you want to calculate the student average each time you need it.

void Print_List(Student List[], int Size)
{
    cout <<left << fixed << setprecision(2) <<showpoint <<endl ;
    cout << setw(19) << "Name" 
    << setw(18) << "ID" 
    << setw(18) << "Average" 
    << setw(16) << "Grade" << endl;

    cout << "=============================================================" << endl;

    for(int i = 0; i < Size;i++)
        cout << setw(19) << List[i].LastName +", "+ List[i].FirstName
        << setw(18) << List[i].Id 
        << setw(20) << calcAverage(List[i])//I use the return value here but it also stores the result in student
        << List[i].Grade << endl;
}
gerard4143 371 Nearly a Posting Maven

Then pass it as a reference.

Something like this

#include <iostream>
#include <string>

void replaceAll(const std::string & oldString, const std::string & newString, std::string & original)
{
    size_t n = 0;
    while ((n = original.find(oldString, n)) != std::string::npos)
    {
        original.replace(n, oldString.size(), newString);
        n += newString.size();
    }
}
int main(int argc, char** argv)
{
    std::string foo("T44 T44 T44 bar");

    replaceAll("T44", "4/4", foo);

    std::cout << foo << std::endl;

    return 0;
}
gerard4143 371 Nearly a Posting Maven

The GCC compiler has a switch -std which can determine the language standard.

Try searching this link for the -std switch options.

http://linux.die.net/man/1/gcc

gerard4143 371 Nearly a Posting Maven

You two errors on line one

for (index = 1; index < SIZE; ++);

for (index = 1; index < SIZE; ++index)
{...}
gerard4143 371 Nearly a Posting Maven

I would go with an array of structures

struct personal
{
    std::string name;
    std::string phone;
    std::string DOB;
};

personal per[10];
gerard4143 371 Nearly a Posting Maven

You could try something like this:

void check_string(const std::string str) { std::cout << "Got->" << str << std::endl; }

void print_actors_movies(treePtr root, const std::string name)
{
  if(root == NULL) return;

  if (root->left) print_actors_movies(root->left, name);

  std::for_each(root->actors.begin(), root->actors.end(), check_string);

  if (root->right) print_actors_movies(root->right, name);
}

I'll leave it to you to check if the name matches.

gerard4143 371 Nearly a Posting Maven
int chdir(const char *path);

You can use chdir() which is in the unistd.h header file.

strRusty_gal commented: Thanks!~ +2
gerard4143 371 Nearly a Posting Maven

No, I want to inistialize the vector from inside the constructor initialization list the goal is not to use the constructor body too, only from the list

I thought I was doing that in my example.

gerard4143 371 Nearly a Posting Maven

Here's a correction implementing some of the changes mentioned above

#include <iostream>

class Base
{
public:
  Base() {}
  ~Base() {}
  void doSomrthing() {}
};

class MyCLass : public Base
{
  std::string name;
public:
  MyCLass();
  ~MyCLass();
  void init();
};

MyCLass::MyCLass()
{
  init(); //runtime error occurs with this line
}

void MyCLass::init()
{
  name = "MyClass";
  doSomrthing();
}

int main()
{}
gerard4143 371 Nearly a Posting Maven

Could it be this

Class

Please note the uppercase C

Or could it be the missing semi-colon here

class Base
{
  Base();
  ~Base();
  void doSomrthing();
}

Or here

Class MyCLass : public Base{
std::string name;
MyCLass();
~MyCLass();
void init();
} 
gerard4143 371 Nearly a Posting Maven

Are you having problems with the ternary operator?

http://msdn.microsoft.com/en-us/library/e4213hs1%28v=vs.71%29.aspx

gerard4143 371 Nearly a Posting Maven

Since your using warnings and strict you should use my.

my $filesize = -s $filename;
gerard4143 371 Nearly a Posting Maven

Should you be using \ here

"C:\Users\bt\Desktop\perl_files";

Shouldn't it be

"C:/Users/bt/Desktop/perl_files";

I think you can the rest here

http://perldoc.perl.org/functions/-X.html

gerard4143 371 Nearly a Posting Maven

This link will show you how to get file size

http://perlmeme.org/faqs/file_io/filesize.html

You'll have to elaborate on date. Do you mean creation data or last accessed date or last modified date?

gerard4143 371 Nearly a Posting Maven

Try this

my @files = sort { $a cmp $b } readdir(DIR);

I tried this and it worked.

#!/usr/bin/perl

use strict;
use warnings;

my $dir = 'directory_path';

opendir(DIR, $dir) or die $!;

foreach( sort { $a cmp $b } readdir(DIR))
{
        next if (/^\./);
        print $_,"\n";
}

closedir(DIR);
exit 0;
gerard4143 371 Nearly a Posting Maven

A pointer is just a variable, so coping a pointer into a pointer is done just like you showed.

    char *name1; 
    char *name2; 

    name2 = name1;

Now both name2 and name1 point to the same memory area.

gerard4143 371 Nearly a Posting Maven
gerard4143 371 Nearly a Posting Maven

On line 27 you have a semi-colon

else if (s[n] == 12); { 

I think that's your problem

gerard4143 371 Nearly a Posting Maven

Well the first thing you'll have to do is determine page size on your computer. Then you could try something like below.

#include <stdio.h>
#include <stdlib.h>

#define MY_PAGE_SIZE 4096

int main(int argc, char** argv)
{
    unsigned long addr = (unsigned long)&main & ((0UL - 1UL) ^ (MY_PAGE_SIZE - 1));
    void * ptr = (void*)addr;/*ptr aligned on page*/
    
    return (EXIT_SUCCESS);
}
gerard4143 371 Nearly a Posting Maven

Well 9 divides into 1 zero times with 1 left over.

gerard4143 371 Nearly a Posting Maven

The error message tells it all. The case needs to be a constant...Like

1,2,3,4,5...or

#define one 1
const unsigned long two 2;

switch(angle)
{
case:1
{}
case:two
{}
}
dij_0983 commented: right :) +2
gerard4143 371 Nearly a Posting Maven

try

std::vector<Rab> items;
jackmaverick1 commented: Perfect +3
gerard4143 371 Nearly a Posting Maven

Sure:

size->4
size->4
size->0022FF4C
size->2293580

~G

I just wanted to make sure you weren't truncating anything..

Now lets look at

int * p3 = "47352";//assign to pointer p3, the pointer that points to "47352"

Unknown (with asterisk): 892548916

*p3 produces 892548916

now 892548916 has a hex value of 0x35333734 which has ascii values

0x35 = '5'
0x33 = '3'
0x37 = '7'
0x34 = '4'

notice that p3 points to "47352" which is an int pointer and int are four bytes on your system so your getting the first four characters of the string "47352".

Graphix commented: Thanks for the help +6
gerard4143 371 Nearly a Posting Maven

For your first function try something like below:

int toNumber(char c)
{
  switch (c)
  {
	case '0':
	  return 0;
	case '1':
	  return 1;
	case '2':
	  return 2;
	case '3':
	  return 3;
	case '4':
	  return 4;
	case '5':
	  return 5;
	case '6':
	  return 6;
	case '7':
	  return 7;
	case '8':
	  return 8;
	case '9':
	  return 9;
	default:
	  return -1;
  }
  return 0;
}

For your second function, what constitutes a space?

gerard4143 371 Nearly a Posting Maven

Try something like this

#include <iostream>

class test {
    public:
        int* num;
    };

int main() {
    test *d = new test;
    d->num = new int;
    *(d->num) = 3;
  std::cout << *(d->num);
}
ProgrammingGeek commented: thanks +1
gerard4143 371 Nearly a Posting Maven

That's a new one 'enum operator'. What's that?

Do you mean something like below?

#include <iostream>

enum colour {red, green, blue};

std::ostream& operator <<(std::ostream & out, const colour & c)
{
  switch (c)
  {
	case red:
	  return out << "red";
	case green:
	  return out << "green";
	case blue:
	  return out << "blue";
  }
  return out;
}

int main()
{	
	
	colour favourite;
	favourite = green;

	std::cout << favourite << std::endl;

	return 0;
}
gerard4143 371 Nearly a Posting Maven

Take a look at this function call

curve = Curve(info, i);

Your passing i = 0 and what do you think will happen in this function when n = 0?

int Curve(Grades g[], int n)
{
int avg, curve, i, data;
int sum = 0;
int count = 0;

for (i = 0; i < n; i++)//n = 0
{
data = g[i].grade;
sum = sum + data;
count++;//never reach this
}

avg = sum / count;//what happens here? count = 0

curve = 75 - avg;

return curve;
}
gerard4143 371 Nearly a Posting Maven
gerard4143 371 Nearly a Posting Maven

If your still having problems try looking at the problem like this:

printf("%s",p + ('E' - 'A'));
gerard4143 371 Nearly a Posting Maven

Sure we'll help fast as soon as you post what you have fast.

Ezzaral commented: Sounds pretty reasonable to me. +16
gerard4143 371 Nearly a Posting Maven

Try looking at it like this:

printf("%s",p + (p[3] - p[1]));

or like this:

printf("%s",&p[4]);
gerard4143 371 Nearly a Posting Maven
gerard4143 371 Nearly a Posting Maven

You can always use try-catch blocks to catch the exception. But in this cases of yours it seems not to need one.
If your method has a return type, you have to return this type in any place in the Sum method. Otherwise the compiler will throw an error.
You can do it:

private void YourMethod()
        {
            int a = -2;
            int b = 3;
            int c = Sum(a, b);
            if (c > 0)
            {
                //Ok!!
            }
            else
            {
                //show a message if needed
                //that some of values are negative
            }
        }

        public int Sum(int a, int b)
        {
            if (a < 0 || b < 0)
            {
                return 0;
            }
            else
            {
                return a + b;
            }
        }

Just a quick question. What happens to your logic when both numbers(a and b) are zero?

Here's what I was suggesting when I mentioned using unsigned integers for parameters

using System;

namespace testit
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			UInt64 x = 0, y = 0;
			bool loop = true;
			
			while (loop)
			{
				try
				{
					Console.Write("Enter value a->");
					x = UInt64.Parse(Console.ReadLine());
					Console.Write("Enter value b->");
					y = UInt64.Parse(Console.ReadLine());
				}
				catch (Exception ex)
				{
					Console.WriteLine(ex.Message);
					continue;
				}
				loop = false;
			}
			
			Console.WriteLine(sum_them(x, y));
		}
		
		public static UInt64 sum_them(UInt64 a, UInt64 b)
		{
			return a + b;
		}
	}
}
gerard4143 371 Nearly a Posting Maven

Your function prototype is incorrect..You have

int giveMemoryBack (CDROM int *pCDROM1, int *pCDROM2, int *pCDROM3)

and it should be

int giveMemoryBack (CDROM *pCD1, CDROM *pCD2, CDROM *pCD3)
{
delete pCD1;
delete pCD2;
delete pCD3;
return 0;
}

and calling your function should be

// Call giveMemoryBack function
giveMemoryBack(pCDROM1, pCDROM2, pCDROM3);
gerard4143 371 Nearly a Posting Maven

I tried something in your code and it seems to work. I essentially knocked the x value back by one if an exception is thrown...

sing System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Exceptional
{
    class WorkerTest
    {
        static void Main(string[] args)
        {
            Worker[] workerArray = new Worker[2];

            int workerID;
            double hrSal;
			
            for (int x = 0; x < workerArray.Length; x++)
            {
                try
                {
			loadId(x, out workerID);
			loadSal(x, out hrSal);

                    workerArray[x] = new Worker(workerID, hrSal);//only reach here if no exceptions thrown
                }

                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
			--x;//knock counter back by one and start again.
                }

            }
            Console.WriteLine();
            for (int i = 0; i < workerArray.Length; i++)
            {
                Console.WriteLine("Worker # {0} \nHourly salary {1}\n--------\n ", workerArray[i].workerID, workerArray[i].hrSal.ToString("C"));
            }
        }
		private static void loadSal(int position, out double val)
		{
			Console.Write("Input an hourly Salary for the worker[{0}]: ", position);
            val = Convert.ToDouble(Console.ReadLine());
			
			if (val < 5.0 || val > 55.0)
			{
				throw new ArgumentException("Unexpected Salary Range.");
			}
		}
		
		private static void loadId(int position, out int val)
		{
			Console.Write("Input a work identification number for worker[{0}]: ", position);
            val = Convert.ToInt32(Console.ReadLine());
		}
    }

    class Worker
    {
        public int workerID;
        public double hrSal;

        public Worker(int WorkerID, double HrSal)
        {
            workerID = WorkerID;
            hrSal = HrSal;
        }
    }
}
gerard4143 371 Nearly a Posting Maven

I just copied and ran your program and it worked.

gerard4143 371 Nearly a Posting Maven

Line 97. What is this

if(s[i].sMaxCap <= h[0,1,2,3,4,5,6,7,8,9].maxCap)
gerard4143 371 Nearly a Posting Maven

In your for statement

for(i = 0; i < 10; i++) {
printf("value, deference pointer, address \n");
printf("pointer1 = %p, *pointer1 = %d, &pointer1 = %p\n", pointer1, *pointer1, &pointer1);
pointer1++;//this line should go last
}

Or better yet.

#include <stdio.h>

int main(void) 
{
	int values[10] = {1,2,3,4,5,6,7,8,9,10};
	int *pointer1;
	pointer1 = values;

	while ( pointer1 < &values[10] )
	{ 
	  fprintf(stdout, "address->%p, value->%d\n", (void*)pointer1, *pointer1);
	  ++pointer1;
	}

	return 0;
}
gerard4143 371 Nearly a Posting Maven

Because the data member is const the = operator can't change its value. So using the = operator on any objects from this class will cause an error.

Your = operator is defined ~ like so

A& A::operator =(const A & obj)
{
if (this != &obj)
{
a = obj.a;//fails here since a is const
}
return *this;
}
Jsplinter commented: Thank you. Clear explanation. +3
gerard4143 371 Nearly a Posting Maven

try

float.TryParse(txtInitialTemp.Text, out temp)
gerard4143 371 Nearly a Posting Maven

what all should i include to make it look decent?

A lot of work....