hey everyone
am totaly stuck on these questions.
am new to programming and a begginer is even a big word for me
i guess am still at the scratch level
so plz help :'(

here are the questions
1. Write a program that asks the user to enter 10 integers. As each integer is entered, only those integers that are odd should be pushed into the stack. The remaining numbers should be ignored. The program should finally pop and print all the items in the stack as output.

2. Write a function called CATSTACK, that concatinates the contents of one stack on top of another. Assume a stack of integers.

Write a program that creates 2 stacks of integers and then concatinates the second one on top of the first one then your program should write all the items by popping them in the resulting stack.

3. Write a program that opens the text file and begins reading the integers. As each inteder is read, checks should be done if the integer is prime, then only one integer (if any) should be popped from the prime stack and printed onto the screen. At the end, the program should also print the number of items still in the prime stack. The data in the text file are 3, 30, 41, 13, 7, 17, 22, 10, 8, 7, 3, 5, 12, 16.

thanks alot for your help

8 Years
Discussion Span
Last Post by Nick Evan

Did you even start/try?

Honestly these look like more than just beginner questions to me. In order to understand data structures, file io, and string manipulation you need to be pretty far into the course.

Are you telling me that you haven't been paying attention this entire time?

class stack {
int counter;
int a[255];

Give it a try to do your homework , it is not that difficult.


1. To check if the number is odd or even, you could use the modules (%) operator. To enter 10 numbers, you could use a loop.

2. Are you allowed to use vectors?

3. Basic file-access. Look into ifstream

Now try to make something yourself. Don't try to make at all at once, but do the requirements 1 step at a step.

Come back when you have some code. Good luck

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.