RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 1552 | Replies: 7 | Thread Tools  Display Modes
Reply
Join Date: Apr 2005
Posts: 4
Reputation: rohitmc is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
rohitmc's Avatar
rohitmc rohitmc is offline Offline
Newbie Poster

need to run these programs

  #1  
Apr 27th, 2005
hi i am new to this forum and my major is computer science...this is the best thing i found on the web yet....i will try to help you out anyway i can.....i need help on this program...thanks




1. create a dynamicarray to hold the first 10 odd intergers. now create the array to triple its size to hold the first 30 odd integers.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2005
Location: Oklahoma
Posts: 63
Reputation: marinme is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
marinme marinme is offline Offline
Junior Poster in Training

Re: need to run these programs

  #2  
Apr 27th, 2005
So, what have you done so far? Do you not understand the assignment?

Hint: use a for loop, the modulus operator with the number two to find if it is even or odd
Yeah... I'm lazy. Deal with it.
Reply With Quote  
Join Date: Aug 2004
Location: Malaysia
Posts: 19
Reputation: Pikachu is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
Pikachu's Avatar
Pikachu Pikachu is offline Offline
Newbie Poster

Re: need to run these programs

  #3  
Apr 27th, 2005
For arrays read here:-
http://www.cprogramming.com/tutorial/lesson8.html

For modulus operator, read here:-
http://www.cprogramming.com/tutorial/modulus.html

You'll be needing for loops also. So read here:-
http://www.cprogramming.com/tutorial/lesson3.html

I suggest you declare a global variable call SIZE (and equate it to 10).
And use the SIZE in your array like this:-
array [SIZE];
and in your for loop also. Like this:-
for (int i=0; i<SIZE; i++)
{
:
do your odd number generator here
and equate it into your dynamic array
:
}

For the second part of the question, just equate SIZE (your global variable) to 30.

Hope this helps.
Reply With Quote  
Join Date: Apr 2005
Posts: 4
Reputation: rohitmc is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
rohitmc's Avatar
rohitmc rohitmc is offline Offline
Newbie Poster

Re: need to run these programs

  #4  
Apr 29th, 2005
ok i will do this...and post here...and if there's any error pls help me out
Reply With Quote  
Join Date: Apr 2005
Posts: 4
Reputation: rohitmc is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
rohitmc's Avatar
rohitmc rohitmc is offline Offline
Newbie Poster

Re: need to run these programs

  #5  
Apr 29th, 2005
ok here we go.....ERRORS...

#include <iostream>
using namespace std;

int main ()
{
	int num_cells=10;
	int * a;
	a * new int[num_cells];
	for (int i=0; i<num_cells; i++)
		a(i)=30*1+1;
	cout<<"a:";
	for (i=0; i<num_cells; i++)
		int=b;
	b=new int [3*num_cells];
	cout<<a(i)<<
		cout <<endl;
	for(i=0; i<num_cells; i++)
		b (i) = a(i);
	delete [] a;
	num_cells *=3;
		a=b;
		b=nul;
	cout << "Size of array has tripled\n";
		for (i=num_cells; i<num_cells; i++)
			a(i>=10*i+1);
			cout<<"a:";
		for (i=0; i<num_cells; i++)
			cout << a [1]<<"";
		cout<<endl;
		delete [] a;
		return 0;
}
<< moderator edit: added [code][/code] tags >>
Reply With Quote  
Join Date: Apr 2004
Posts: 3,808
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 147
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: need to run these programs

  #6  
Apr 29th, 2005
Arrays are indexed a[i], not a(i).
a * new int[num_cells];
Typo?
a = new int[num_cells];
Did you mean i instead of int? b? nul?

Learn to use whitespace to make your code easier to read.
High Plains Blogger #plains #lounge ## I, for one, welcome our new socialist overlords.
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
Reply With Quote  
Join Date: Aug 2004
Location: Malaysia
Posts: 19
Reputation: Pikachu is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
Pikachu's Avatar
Pikachu Pikachu is offline Offline
Newbie Poster

Re: need to run these programs

  #7  
Apr 30th, 2005
Well, your codes are a little misleading. I don't quite understand what you are doing. Anyway, I'll go step by step with you. First, make sure you have this in mind:- A 10 block array like this [] [] [] [] [] [] [] [] [] []

for (int i=0; i<num_cells; i++)
		a[i]=30*1+1;
cout<<"a:";
Here, I can only interpret one thing. The array will be filled with number 31 like this:- [31] [31] [31] [31] [31] [31] [31] [31] [31] [31]
But on screen you'll only see a: as you didn't include the output into your loop

Then, I see that you transfer the array a to array b. Which I do not see the need for this. But please correct me if I'm wrong
for(i=0; i<num_cells; i++)
		b [i] = a[i];


for (i=0; i<num_cells; i++)
	cout << a [1]<<"";

If everything works well, you'll only get something like this a [1]a [1]a [1]a [1]a [1]a [1]a [1]a [1]a [1]a [1]

The rest of the problem, I believe Dave had already mention them.
Reply With Quote  
Join Date: Apr 2005
Posts: 4
Reputation: rohitmc is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
rohitmc's Avatar
rohitmc rohitmc is offline Offline
Newbie Poster

Re: need to run these programs

  #8  
May 6th, 2005
thanku for all the help...i will give another shot and post it here....
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the C++ Forum
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:18 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC