richieking 44 Master Poster

sure well said; on line 1 ; is the bad fox.

richieking 44 Master Poster

And i guess he need to initialize the first clock outside the while loop so that there will be a difference in the starting and outside the finished while loop get a new clock to minus the starting time from the ending time and the results is the time taken. Like a lazy benchmark 101.

richieking 44 Master Poster

can you tell us what each function is suppose to do in your code. comments please.

richieking 44 Master Poster

You are welcome.

richieking 44 Master Poster

No he will not. We help but not solve the problem. Ask your friend to provide what he has done so far.

richieking 44 Master Poster

Work on code readability mate. format your code well then repost ok?

richieking 44 Master Poster

Errors fixed.
Now work on your magic function

#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

void PrintMatrix( int x[][20], int size)
{
    for(int i = 0; i < size; ++i)
    {
        for(int j = 0; j < size; ++j)
        {
            cout << x[i][j] << "\t";
        }
        cout << endl;
    }
}
int SumRtDiag(int x[][20], int size)
{
    int d = 0;
    for(int i = 0; i < size; ++i)
    {
        d += x[i][i];

    }
    return d;
}
void DataIn(ifstream &fin, int x[][20], int size){


    for(int i = 0; i < size; ++i)
    {
        for(int j = 0; j < size; ++j)
        {
            fin >> x[i][j];
        }
    }
}
int SumCol(int x[][20], int size, int NumCol)
{
    int ColSum = 0;
    for(int i = 0; i < size; ++i)
    {
        ColSum += x[i][NumCol];
    }
    return ColSum;
}
int SumRow(int x[][20], int size, int NumRow)
{
    int RowSum = 0;
    for(int j = 0; j < size; ++j)
    {
        RowSum += x[NumRow][j];
    }
    return RowSum;
}
int FindSize(int x[][20], ifstream &fin)
{
    int m;
    fin >> m;
    return m;
}
int SumLftDiag(int x[][20], int size)
{
    int sum = 0;
    for(int i = 0; i < size; ++i)
    {
        for(int j = 0; j < size; ++j)
        {
            j = size - (i + 1);
            sum = x[i][j];
        }
    }
    return sum;
}
bool IsMagic(int x[][20], int size)
{
    int total;
    total = SumRtDiag(x , size);
    if(total != SumLftDiag(x, size))
    {
        for(int i = 0; i < size; …
richieking 44 Master Poster

If you cant get this to work, then i guess if i produce the whole code you still can not get that to work either. Show me what you have done so far.....

richieking 44 Master Poster

And if i were you, i will bring in the class object inside the main. Then the initialize fucntion a template so that you can use that for both class.

template<class T, int size>
void init(T, size){
// Then you can initialize all you class

}
richieking 44 Master Poster

A little update

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

int main(){
personal per[10];

static short count=0;
while(count <10){

//ask for name entry
//then cin
cin>>per[count].name;
//ask phone
cin>>per[count].phone;

cin>>per[count].DOB;
count++;

}
return 0;
}
richieking 44 Master Poster

You can also use the cpp11 lambda and the for_each in the algorithm as follows.

#include <algorithm>
#include <iostream>
#include <iterator>
using namespace std;
int main()
{
    int a[] = {1, 2, 3, 4, 5};
    int i = 2;
    cin >> *(a + i);
    copy(a, a + 5, ostream_iterator<int>(cout, " "));

    // Or you can use lambda as follows
    for_each(a,a+5,[](int &c){cout<<c;});// also very useful.

    cout << '\n';
}
richieking 44 Master Poster

Thats very simple and easy. wow... so simple task. But no one willdo that here for you. oooch!

So if you want our attention.... then show some code will you?

richieking 44 Master Poster

As deceptikon has explained earlier,
I also wish to add something further to it.
*(0+a) is equal to calling *a or a[0].
when you add the ofset data to the pointer*(2+a) , you just ask the pointer to move to the said memory space then defference the pointer with (*) whiles the pointer has moved to the ofset.

This is called pointer arithmatic.

richieking 44 Master Poster

If you need more info about linux .so link. Get back for that ok? The concept is not too different.

richieking 44 Master Poster

Your problem is number 12 in the while loop. The logic was not right.
try this

string data;
static int count=0;
while(getline(d_file,line)){
    data +=line;
    count++;
    if(count==2){
        user_vec.push_back(data);
        count=0;
    }
}

you caould have had the data setup the way you want before inserting into the vector. Its called planning.

richieking 44 Master Poster

start with some googling ok? Here we do not teach people but we share ideas. Its a give and take show. not take take ok?

come again when you want to comply. Thank you.

richieking 44 Master Poster

What is the error output. can you post that here also?

richieking 44 Master Poster

you have to look carefully into cpp input output stream and files. When you open a file, there are constants that you need to include in the open comand.
1. To append,
2.to truncat
3. open as a binary
etc.... or all of the following

I think it is like this ofstream out("foo.txt",ios::app);
check it up ok?

richieking 44 Master Poster

counted_ptr must be a template/generic type which is well designed.

template<class T>
count_ptr{
  count_ptr():t(tp){}
  operator()(){}
  operator +(){}
  operator=(){}
private:
  T t;
};

int main(){
//class foo object  bar
foo bar;

// now count_ptr serves as a container that can accept and manipulate class 
//foo objects.
count_ptr<bar> count_ptr_bar.


}

get back to the basis of generics.
send from my phone so its not a working code. just the righ path.

richieking 44 Master Poster

there are various questions that comes to mind.
1. how was the main file written? ie. is it encrypted ?
-if yes, you will need the encrypted key/pass to get the real data.
- if no, then you must know how to use the compressed lib verywell to use it to decompress the data which i think its not possible...
why because his encryption might be done on Nth times. Datas are encrypted to keep people like you not to poke their noses into peoples secrets else no need for that at all. got it?

richieking 44 Master Poster

change line 39 to double housePrice[PRICES];and on line 52 in while loop change 999.0 change all int needed to double for checkups. You should be fine

richieking 44 Master Poster

printer is a very low-level stuff. there are hundreds of libs out there but you must consider a GUI like QT thats a multi platform. The best GUI in town.

richieking 44 Master Poster

lambda is also another way out. consider looking into that.
I personally like lambda when it comes to what you are requesting. Clean and mmm simple. That is depends on your knowledge with cpp11.

richieking 44 Master Poster

Your code runs without error on my ubuntu Qt5.1.
Can you post your error?

richieking 44 Master Poster

online 43. set up a static int counter =0;

then increment the counter in the while loop . check with if the counter is equall 3 break or else keep asking for the password to be entered correctly.
simple.

richieking 44 Master Poster

Also i guess you need to look into recursive fucntion as you could accomplish this task easy with that. i hate long codes. it makes me wanna sleep. long codes are more error prone.

richieking 44 Master Poster

Also consider xml type as its more structured. Thats depending on your level lol. My favorit here is sqlite but i guess you wont need that for now. Experiment.... keep on.

richieking 44 Master Poster

so what have you done personally here. Do something, show your errors and we might/may help you. Thats how we do it over here.

richieking 44 Master Poster

help yourself.

ofstream fw("foo.txt");
fw<<"write me "<<endl;
fw.close();
richieking 44 Master Poster

No one will go the those link for you. Provide your code and your errors and we might have a look at them.

we dont get paid for anything here... remember that.

richieking 44 Master Poster

That says all about MS VC++. I compiled and run copy on my phone, later at home on my ubuntu and that was perfect. Also sure copy uses memmove() because C++ is build on C but copy is one of the best and easy way to achieve the said trivial task. Thats my take. ;-)

richieking 44 Master Poster
int main(){

std::fuction<void(const &a,void)>pp =&a::message();
pp();
return 0;
}

you need to write your class well. look into it more cpp0x help on fuctional.

richieking 44 Master Poster

that was not my intention.... i wanted to explain or proof why i support the copy method instead of the old style iteration.

Also the las code was a typo i made.

int *exp(int *arr, int size){
    int *temp=new int[size*2];
        temp=arr;
        for(int i=size;i<size*2;i++)
            temp[i]=i*2;
    return temp;
}

the mistake was using simgle data alloc.
ofcourse this can be optimised to call delete on temp.
Whats your say Dragon? I need your view mate. yea it trivial but hay is fun.

richieking 44 Master Poster

or this.

int *exp(int *arr, int size){
    int *temp=new int[size*2];
    for(int x=0;x<size;x++)
        temp[x]=arr[x];
    return temp;
}

but for quality... i will use the copy method.

richieking 44 Master Poster

You are right if you go about it that way.
Another best form is to use the Algorithm copy.
like this

int *exp(int *arr, int size){
    int *temp=new int(size*2);
    copy(arr,arr+size,temp);

      return temp;
}
richieking 44 Master Poster

Asigning array of the same data type which is bigger copies the data. so i think its more efficient this way.

nt *exp(int *,int);

int main(){

    int ar[]={4,3,7,5,7,8,6,5,4,2};
    int *foo;
    foo = exp(ar,10);
    for_each(foo,foo+10,[](int &c){ cout <<c<<endl;});


  return 0;
}


int *exp(int *arr, int size){
    int *temp=new int(size*2);
      temp = arr;
      return temp;
}
richieking 44 Master Poster

using namespace std;

richieking 44 Master Poster

You need to run your pointer in a loop and randomly insert NULL.
pseudo code...

for(n=0;n<10;n++)
  for(y=0;y<10;y++}
    if(y%2==0)
       p[y][x]=NULL;
    p[y][x]=y+x;

Hope this help.

richieking 44 Master Poster

should be a pratice to always use int main(). Main in cpp is not void.
With your args, i think you are not entering it right or some other stuff you are not doing it right.

richieking 44 Master Poster

You can read the entire data using geline. Then use gcount() function to give you char numner inside the file.

 i
richieking 44 Master Poster

The code seems too much C style to me. why couldnt you just use a proper CPP style. And could even make it 3 lines once you get the idea.

 ifstream file("text.txt"); //open file
    string stuff,cc;
    if(file.is_open()){ // check file if success
        while(!file.eof()){
          file >> stuff;  // put line date here
         cc +=stuff;   //append data
          } 
          cout <<cc.length(); // use the length method
    }
    else
    {
        cout <<"error"; // error checking
        }

  file.close(); //house keeping
richieking 44 Master Poster

Open your file before the do statement on number 27.
You keep opening file which is already open..
That can truncat data and most compilers will give fatal error. Its not done. put it ouside the loop.

Also use string ans = ifFile.is_open()?" file open ":"Error";

Not specifially this style but the is_open() fucntion/method that you must use to test open file. very rubost.j

richieking 44 Master Poster

Guys looking at the post carefully, the poster's code is still not answered. He wanted to print a linklist data and then delete the last node. looking at his print function, it looks like he was trying to build a doubly link list not a single list. This is why he started 2 while iterations. If he was working on a linklist, there was not need for a double iterations at all. why double iterations for? whats the point ...?. Like Ancient Drogon asked?

If thats not the case, then i think the poster must come out clearer what he intend to achieve.

richieking 44 Master Poster

maybe he needs a const char* just to print it out. what else ?.... can we both agree that he should get back to basic oop and data types classroom again. just my opinion.

richieking 44 Master Poster

your code is even more error prone. memory leaks.
new allocation always need to be freed.
On line 16. for something simple like this, there was no need using new alloc. just simple

const int foo=10;
int afoo[foo];

something more simpler and effective for basic data ops. The point is you are allowed to do as you please but clean our mess after.

Just a cup of coffee advice.

richieking 44 Master Poster

he got no code guys. use your imarginations. we are gods!

richieking 44 Master Poster

Try this style.
Also you can read the value into an array or just cout. Its even more easier once you know that value format remains the same.

using namespaces std;
string line = "foo: bar: boo:tuna";
string del = ":";

size_t pos = 0;
string token;
while ((pos = line.find(del)) != string::npos) {
    token = st.substr(0, pos);
    cout << token << endl;
    st.erase(0, pos + del.length());
}
cout << st << std::endl;

foo
bar
boo
tuna

richieking 44 Master Poster

A dongling pointer. This is C++ not VB or Javascript...
no var variable here please.

richieking 44 Master Poster

MixedExpression.cpp.
Look at line 94 bout printdata method. The logic is not right.
You seem to read data to out output file object but not printing to screen. check your logic and debug well.

richieking 44 Master Poster

Your indentaion is very poor. work on that first ok?