Wrox Programmer Forums
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 31st, 2009, 12:49 AM
Registered User
 
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default C++, help please!

I need to write programs that do the following (using c++ visual of course, I use visual 6.0!):

1-Write a program that checks if a sequence of positive numbers is in increasing order or not.

should I use a for loop here and an if statement, if yes how?

2- Find the greatest divider of two positive integers..



and finally,
Starting with the first value of a list (ending with -1) print only the sub-list of values in increasing order.

Example:
Input: 1 4 2 7 3 9 6 -1
Output: 1 4 7 9


and NO this is not a homework, those are some practice problems that I was trying to solve....I have an exam on these things on Tuesday!!
any help would be really appreciated!!! thanks in advance!


Last edited by iwillsurvive; May 31st, 2009 at 01:21 AM..
 
Old May 31st, 2009, 07:51 AM
Registered User
 
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

here is what I've tried for the second Q:
#include<iostream.h>
void main()
{
int m,n;
int max=0;
do{
cout<<"enter two positive numbers:";
cin>>m>>n;
if((m>0)&&(n>0))
{
for (int i=1;i<=m;i++)
for (int i=1;i<=n;i++)
{
if ((m%i==0)&&(n%i==0))
if (i>max)
max= i;
}
cout<<"the greatest dividor of"<<m<<"&"<<n<<"is"<<max;
}
else
cout<<"whatever";
}while ((m>0)&&(n>0));
}


for the other two questions, I have no idea from where or how to start!!

Last edited by iwillsurvive; May 31st, 2009 at 07:53 AM..
 
Old June 1st, 2009, 05:55 AM
Registered User
 
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hmm...my exam is tomorrow, any idea on how to do the other two questions?!
 
Old June 2nd, 2009, 01:22 AM
Registered User
 
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

as I expected, no one tried to help!!! thanks for letting me down :)
 
Old June 9th, 2009, 02:28 PM
Friend of Wrox
 
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
Send a message via ICQ to iceman90289 Send a message via AIM to iceman90289
Default

ok. well i havent been on since may...

as far as the way you asked for help... it would be better if u came up with your own ideas and asked us why it didnt work when u tried it...

like for example.. im having an issue creating a "dummy object" in a function... that will be in my next post. and im certain i will get a reply... because i didnt throw the project outline at the forums..

woulda been happy to help had i read ur post earlier..

type code in the code tags like this "
Code:
" and "
"
 
Old June 12th, 2009, 10:39 AM
Registered User
 
Join Date: May 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

well, I'm new here or I "was" new and thankfully I'll no longer need to use any programming application....even If I did write what I came up with, no one would have replied!! anyways thank you for replying, I really appreciate it! and best of luck finding someone who will answer you!!
 
Old August 11th, 2009, 08:09 AM
Authorized User
 
Join Date: Aug 2009
Posts: 18
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Answer of first question is simple:
Code:
int n=10; //number of array members
int myarray[n]=new array[];
int min, max, count=0, count_neg = 0; //those variables (min,max) are used to determine which number is bigger
int i;

min=myarray[0]; //first initialisation of min variable on first member of array
for (i=0;i<n;i++)
{
  if(min<myarray[i]) //if array is ascending
    {
       min = myarray[i];
       count++; //internal counting, if maches with n that means that array is complete
    }else if (max>myarray[i]) //if array is descending
    {
      max = myarray[i];
      count_neg++; //second internal counting, if maches with n that means that array is complete
    }
if (count = n)
  {
    cout<<"The array is ascending!"<<endl;
  }else if(count_neg = n)
  {
    cout<<"The array is descending!"<<endl;
  }else
  {
    cout<<"The array is not in order!"<<endl;
  }
}
 
Old August 11th, 2009, 08:22 AM
Authorized User
 
Join Date: Aug 2009
Posts: 18
Thanks: 2
Thanked 0 Times in 0 Posts
Default

And the third answer is even simplier than second.
What you need to do is just determine that next number is bigger than previous one.

Code:
int n; //number of array members
int myarray[n]=new array[]; //duno is this real declaration of array, check!!!
int i = 0;
int max = myarray[0]; //declaration with init. on first member of array

for(i=0;i<n;i++)
{
   if(max>myarray[i])
      {
         max = myarray[i]
         cout<<max<<"\t";
      }
}
What is the case here, we just check if next number is bigger than previous, and if it's case, than we use that value and compare it to next and so on.

P.S. And check the sintax, here i don't have C++ installed.

Last edited by Lupus81; August 11th, 2009 at 08:25 AM..









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.