Hi to everyone. It's my first post here and I'd like to get some help.
A friend of mine has 2 (simple for you) problems to solve and she doesn't have a clue (and nether do I).

Prob 1.) Write a code in C++ (visual) that reads from the keyboard integer numbers and saves them at a table (of integer numbers) of two dimensions with n rows and n columns.
Next it should do the folowings:
a) Show the contents of the table on screen
b) Find the biggest number of each row
c) Find the smallest number of each column
d) Find the quantum of the odds and of the evens
e) At the end of the program, it should show all the previous results on screen


Prob 2.) Write a code in C++ (visual) that reads from the keyboard integer numbers and saves them at a table (of integer numbers) of two dimensions with n rows and n columns.
Next it should do the folowings:
a) Show the contents of the table on screen
b) Sort the evens of each row from the smallest to the biggest and the odd of each row from the biggest to the smallest.
e) At the end of the program, it should show the previous result on screen

Shes only knows the basics and "do-while" and "for".

If anyone could help me, I'd be grateful. Please, please, please!!
Thank you in advance.

Recommended Answers

All 15 Replies

I've just read the "read me..."
I know I'm wrong and I apologize. But I'm just asking for help. This friend of mine is studying chemistry in Greece. In chemistry, there's no need to know C++, but in greek university seems that knowing c++ is helpful in chemistry!!! Who knows!! Anyway, the only thing i/she wants is just to pass the class so that she'd be able to continue. Nothing more.
If anyone could help me, please do.
Thank you and I'm sorry.

I am only new here, but is really surprising (and saddening) how many people just post up their assignments hoping someone else will do the ALL the work.

As an employer of IT graduates I get to read a lot of CV's an interview a lot of candidates. And to be frank the majority of them are rubbish and it is easy to see why.

It only takes 5 mins in an interview to work out who are the people who 'don't have a clue'. So while you might pass your assignment, by copying the work of others, ultimately you still won't get a good job in IT. The sham will be exposed during the first few interview questions.

For a laugh I ask the computer science graduates how a computer works. I get answers like, 'you push the power button, then type on the keyboard to make it work'. Roughly the same answer a 10 year old would give. Needless to say some of the interviews are very short and end in tears.

So better to either make half an effort to study the material, or give up now and do someone that is more suited to your skills.

I am only new here, but is really surprising (and saddening) how many people just post up their assignments hoping someone else will do the ALL the work.

As an employer of IT graduates I get to read a lot of CV's an interview a lot of candidates. And to be frank the majority of them are rubbish and it is easy to see why.

It only takes 5 mins in an interview to work out who are the people who 'don't have a clue'. So while you might pass your assignment, by copying the work of others, ultimately you still won't get a good job in IT. The sham will be exposed during the first few interview questions.

For a laugh I ask the computer science graduates how a computer works. I get answers like, 'you push the power button, then type on the keyboard to make it work'. Roughly the same answer a 10 year old would give. Needless to say some of the interviews are very short and end in tears.

So better to either make half an effort to study the material, or give up
now and do someone that is more suited to your skills.

I agree with you.
But, first this isn't my assignment, but a friend's of mine.
Secondly, she is NOT going to be an IT (she only knows how to use a pc), but she'll graduate with a chemistry degree. She doesn't even know why she should study c++, but she has to. Even the professor she has tryies to help them but she doesn't have a clue about c++. That's why she is asking for help.
Anyway, it's your call.

I agree with you.
But, first this isn't my assignment, but a friend's of mine.

Exactly. It's her assignment, not ours. We are not going to do her work for her. We don't get the grade.

She doesn't even know why she should study c++, but she has to.

So, it's a requirement for her to study C++? And you feel that's stupid so it's better to have us do her work? Think again. A requirement is a requirement. If she can't do it, change to a school that doesn't have that requirement.

Even the professor she has tryies to help them but she doesn't have a clue about c++. That's why she is asking for help.

No, she's not asking for help. You're asking us to do it for her. That's not help. That's charity.

Anyway, it's your call.

No, it's her call. Wouldn't be better to have her post, instead of you? After all, who has the problem? Maybe she can follow the rules better than you since she has the code.

but she'll graduate with a chemistry degree...

I had to do organic and inorganic chemistry to get a degree in computer science (and maths, physics, astronomy and philosophy).

At the time I thought it was dumb, but 20 years on, I don't regret doing it. It is useful from time to time.

Except for philosophy, which really was dumb :)

All science students should learn some computing IMHO. They'll use it.

Exactly. It's her assignment, not ours. We are not going to do her work for her. We don't get the grade.

No, she's not asking for help. You're asking us to do it for her. That's not help. That's charity.

"You don't get the grade", "that's charity".
Next thing is to send me your bank account!! I asked for help. Do you know what does the word "help" mean? What am I saying? You are mr smart guy, of course you know.
I didn't make you to do it. I asked from all of you, very very politely i believe, to help me do it. If you don't want to help, just don't. Just don't brake my balls, ok?

So, it's a requirement for her to study C++? And you feel that's stupid so it's better to have us do her work? Think again. A requirement is a requirement. If she can't do it, change to a school that doesn't have that requirement.

I won't even bother to explain, especially to you, of what I think or what I believe. As I told before, if you don't want to help, just don't. Maybe there are others here who are kind enough to help, or at least have the right manners to say no. I have never made anyone do something didn't want to.
Oh, sorry, I forgot. You are the smartass of the forum, so you absolutely have to say something, even if you don't know why.

No, it's her call. Wouldn't be better to have her post, instead of you? After all, who has the problem? Maybe she can follow the rules better than you since she has the code.

Hey Einstein, as I wrote before, she barely knows how to use a pc, you expect her to post in here? And by asking me for help, means that she wants someone to tell her how to do it. She doesn't care if I knew it myself, or asked you. Otherwise, she would do it by herself. Dah!!
And as for the rules. I am member in lots of forums for many years. I have never done anything that is braking the rules. I know I've done it know, in purpose, and when I was told (it's the second post), I apologized politely and just asked if anyone could help me.
I't the first time in my life that I speak/write to someone in a forum in a bad way, and for that I apologize from all of the other users, but I can't stand ανυ wise guy talking to me like this. You don't know me, you should respect me, and you should behave better. I'm not the only one braking the rules here you know.

Anyway, I spent much more time for you than you even worth, it's time to go.
Thank's for being a dick. At least you are real, you are yourself.
Goodnight.

I had to do organic and inorganic chemistry to get a degree in computer science (and maths, physics, astronomy and philosophy).

At the time I thought it was dumb, but 20 years on, I don't regret doing it. It is useful from time to time.

Except for philosophy, which really was dumb :)

All science students should learn some computing IMHO. They'll use it.

You know, I believe you are right. It would be useful to learn how to use a computer. Very useful indeed. But how do you expect from someone who doesn't know almost anything about pc's, to make programs with c++. Even the smallest ones!! :confused:
And i really can't understand, where would c++ help her as a chemical!! :-/

Anyway. First problem is solved. It took me a day for something that most of you would spend just a few minutes :$ , but at least I've done it. Now I have to do my best for the second one.
Thank you all for your time and have a good night.:zzz:

"You don't get the grade", "that's charity".
Next thing is to send me your bank account!! I asked for help. Do you know what does the word "help" mean? What am I saying? You are mr smart guy, of course you know.
I didn't make you to do it. I asked from all of you, very very politely i believe, to help me do it.

No, you didn't "ask very politely to help you do it". You asked us to give you the solution without any effort on your part. Those are two very different things. I don't know about you, but I sure don't define 'help' as giving someone the answer.

Hey Einstein, as I wrote before, she barely knows how to use a pc,

If she barely knows how to use a PC, she has no business in a programming course. What part of this can't you understand?

And as for the rules. I am member in lots of forums for many years. I have never done anything that is braking the rules. I know I've done it know, in purpose, and when I was told (it's the second post), I apologized politely and just asked if anyone could help me.
I't the first time in my life that I speak/write to someone in a forum in a bad way, and for that I apologize from all of the other users, but I can't stand ανυ wise guy talking to me like this. You don't know me, you should respect me, and you should behave better. I'm not the only one braking the rules here you know.

On the contrary. WaltP has been conducting himself in a very clean, professional manner. I can't say the same about you, however.

Thank's for being a dick.

Oh, the irony.

I had a long response but decided to recap very simply:

All you need to do is post a question that we can answer. Rather than doing that you got huffy at us. Sorry 'bout that, but we can't respond to a non-question.

If you'd like to start again and actually post code and ask an answerable question, we'll still help. We just won't write the programs for you. Simple as that.

WaltP
What you wrote above is really acceptable and I can understand it. If only you'd answer this way yesterday, and I wouldn't feel the way I did, so I wouldn't react the way I did. I'm realy sorry about that.
I would like to start again and delete all the above.
Now, I'd like your help with the problems I wrote at my first post. I have only "solved" problem 1, but it's not 100% right
I wrote some code, but somewhere there's a leak.
This is the code:

#include <stdio.h>
#include <stdlib.h>
int main()
{
int i, j, m, n, z, p, max, min;
int pinakas[j];
printf("Poses grammes thelete na exei o pinakas?: ");
scanf("%d",&m);
printf("Poses sthles thelete na exei o pinakas: ");
scanf("%d",&n);
for(i=0; i<m; i++)
{
printf("\n***** %dh grammh *****\n",i+1);
for(j=0; j<n; j++)
{
printf("Parakalo eisagete ton arithmo gia th %dh sthlh:",j+1);
scanf("%d",&pinakas[j]);
}
}
for(i=0; i<m; i++)
{
printf("\n");
for(j=0; j<n; j++) printf("%-5d", pinakas[j]);
}
printf("\n\n\n");
for(i=0; i<m; i++)
{
max=0;
for(j=0; j<n; j++) if(pinakas[j]>max) max=pinakas[j];
printf("O megaluteros arithmos ths %dhs grammhs einai %d\n", i+1, max);
}
printf("\n\n");
min=9999;
for(j=0; j<n; j++)
{
z=0; p=0;
min=9999;
for(i=0; i<m; i++) if(pinakas[j]<min) min=pinakas[j];
printf("O mikroteros arithmos ths %dhs sthlhs einai %d\n", j+1, min);
}
for(i=0; i<m; i++)
{
for(j=0; j<n; j++) if((pinakas[j]/2)*2==pinakas[j]) z=z+1;
else
p=p+1;
}
printf("\n\nOi artioi einai %d kai oi perritoi einai %d\n\n", z, p);
system("pause");
return 0;
}

At first it seemed right, but try a table 5x5 and watch the results.
The words that are in the brackets, in the "printf" command, are greek written with latin alphabet.
Poses grammes thelete na exei o pinakas? = how mane rows do you want
Poses sthles thelete na exei o pinakas = how many columns do you want
Parakalo eisagete ton arithmo gia th %dh sthlh = please insert number for %d column
O megaluteros arithmos ths %dhs grammhs einai %d\n = the biggest number of the %d row is %d
O mikroteros arithmos ths %dhs sthlhs einai %d\n = The smallest number of the %d column is %d
Oi artioi einai %d kai oi perritoi einai %d = The evens are %d and the odds are %d

Tried to translate them into english, but when I run the program, it was giving me an error message.
I'm stuck here without knowing what to do now.
Any ideas?
Thank you.

If you use code tags (you can read about them in the stickies above or in the blue watermarks that appear in the message box before you start typing/pasting in it) then the indentation you (hopefully) use in your code will be maintained in the post. It's a bit of hassle, but minimal.

This is the C++ board. The code you wrote uses pure C syntax, and as such, although it technically can be run as C++, may be better posted in the C forum.

That being said, I can offer the following comments.

It is wise to post the error message you have received so we can address the issue involved rather than making a guess. Here's a couple guesses.

If you compiled this using a C++ compiler that is standards compliant you may have gotten a warning that stdio.h and and stdlib.h are no longer the prefered header files for C input etc when used in C++. The prefered version of the header files would be cstdlib and cstdio. That probably wasn't the error message however.

In both C and C++ when declaring arrays using static memory, as in this line:

int pinakas[j];

the dimensions i and j need to be constant integers. However, in this line;

int i, j, m, n, z, p, max, min;

i and j are declared as variable integers. To allow the user to input the dimensions of the array you would need to use dynamic memory rather than static memory. That requires use of the keywords malloc() (C syntax) or new(C++ syntax). I'll try to give a C version, but it's not my prefered language.

int rows, cols, i, j;
int pinakas **;
printf("Poses grammes thelete na exei o pinakas?: ");
scanf("%d", &rows);
printf("Poses sthles thelete na exei o pinakas: ");
scanf("%d", &cols);
pinakas = (int*)malloc(rows);
for(i = 0; i < rows; ++i)
  pinakas[i] = (int*)malloc(cols);

Eventhough pinakas is declared as a pointer to pointer, it will behave as 2 dimensional array (table) in all respects.

Technically you should release any memory you declare with malloc() or new once you are done with it. I believe the keywords are free (C syntax) and delete[] (C++ syntax for releasing memory declared in contiguous blocks). However, the memory should be released as the program terminates, so that isn't really a major problem in the current program.

There's a big typo in my prior post. It should be int ** pinakas not int pinakas **. Sorry.

Thanks you for your answer. I'm going to check this out later.
The error I get is this.

Well, I've done it. Both problems are now solved. Thank all of you who tried to help me very very much.
It was a bit difficult for me, but it's over now!!
Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.