C++ Question

  • ainab
  • Newbie
  • Newbie
  • ainab
  • Posts: 6
  • Loc: finland

Post 3+ Months Ago

Does any one can help about this c++ program:

A program in which you define two separate arrays of type Property
data structure (in lecture II) and uses pointers to compare, find and
print out those elemnts of arrays which are equal in both arrays; values for
house, car and boat are the same.*/
Code: [ Select ]
#include <iostream>
using namespace std;


struct Property{
char house[10];
unsigned short car;
unsigned short boat;
};

int main() {

int i;
Property Friends[] = { {"Yes", 0, 2}, {"No",1, 0}, {"No", 0, 0} };
Property Friend[] = { {"Yes", 0, 2}, {"No",1, 0}, {"No", 0, 0} };
Property *p,*p1;
p=Friends;
p1=Friend;

        while(*p==*p1)
 
        {
     if(*p == *p1)
        {
        (p)++;
        (p1)++;
        }    
        
        else
        {
        
    for(i=0; i<3; i++)
         {
    cout<<"\nFriends "<<(i+1)<<" owns a house? "<<p[i].house;
        cout<<"\tFriends "<<(i+1)<<" owns "<<p[i].car<<"car(s).";
        cout<<"\tFriends "<<(i+1)<<" owns "<<p1[i].boat<<"boat(s).";

    (p)++;
        (p1)++;
}
  1. #include <iostream>
  2. using namespace std;
  3. struct Property{
  4. char house[10];
  5. unsigned short car;
  6. unsigned short boat;
  7. };
  8. int main() {
  9. int i;
  10. Property Friends[] = { {"Yes", 0, 2}, {"No",1, 0}, {"No", 0, 0} };
  11. Property Friend[] = { {"Yes", 0, 2}, {"No",1, 0}, {"No", 0, 0} };
  12. Property *p,*p1;
  13. p=Friends;
  14. p1=Friend;
  15.         while(*p==*p1)
  16.  
  17.         {
  18.      if(*p == *p1)
  19.         {
  20.         (p)++;
  21.         (p1)++;
  22.         }    
  23.         
  24.         else
  25.         {
  26.         
  27.     for(i=0; i<3; i++)
  28.          {
  29.     cout<<"\nFriends "<<(i+1)<<" owns a house? "<<p[i].house;
  30.         cout<<"\tFriends "<<(i+1)<<" owns "<<p[i].car<<"car(s).";
  31.         cout<<"\tFriends "<<(i+1)<<" owns "<<p1[i].boat<<"boat(s).";
  32.     (p)++;
  33.         (p1)++;
  34. }
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • digitalMedia
  • a.k.a. dM
  • Genius
  • User avatar
  • Posts: 5149
  • Loc: SC-USA

Post 3+ Months Ago

I split this from a thread in the General Discussion.

Good Luck.
:)

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: Bogey, Liamw411 and 54 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.