| | |
need to run these programs
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
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.
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.
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++)
{
For the second part of the question, just equate SIZE (your global variable) to 30.
Hope this helps.
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.
ok here we go.....ERRORS...
<< moderator edit: added [code][/code] tags >>
C++ Syntax (Toggle Plain Text)
#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; }
Arrays are indexed a[i], not a(i). Typo? Did you mean i instead of int? b? nul?
Learn to use whitespace to make your code easier to read.
a * new int[num_cells];a = new int[num_cells]; C++ Syntax (Toggle Plain Text)
int=b;
C++ Syntax (Toggle Plain Text)
b=nul;
Learn to use whitespace to make your code easier to read.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
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 [] [] [] [] [] [] [] [] [] []
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
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.
C++ Syntax (Toggle Plain Text)
for (int i=0; i<num_cells; i++) a[i]=30*1+1; cout<<"a:";
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
C++ Syntax (Toggle Plain Text)
for(i=0; i<num_cells; i++) b [i] = a[i];
C++ Syntax (Toggle Plain Text)
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.
![]() |
Similar Threads
- Windows emulator to run mIRC (*nix Software)
- he's kick'n it old school. (Geeks' Lounge)
- Do all programs in Windows XP compactible in Linux? (Getting Started and Choosing a Distro)
- Should I major? (Computer Science)
- Compiling Programs (C++)
- Doubts about spyware fixer programs (Viruses, Spyware and other Nasties)
- Internet Explorer Running SLOW (Web Browsers)
- Java vs Java3D (Java)
Other Threads in the C++ Forum
- Previous Thread: postfix evaluation
- Next Thread: Help. This is a strange problem
Views: 1760 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






