Docsity

C++ Program for Structuring Person's Data with NIC and Height, Exercises of Object Oriented Programming

Toggle sidebar
bg1
1C:\DocumentsandSettings\Administrator\My...2010\Projects\structure\structure\structure.cpp
#include<iostream>
#include<conio.h>
usingnamespacestd;
structNIC
{
 intfield1;
 intfield2;
 intfield3;
};
structRecord
{
 charfirst
_
name[10];
 charlast
_
name[10];
 NICidentification
_
number;
 intheight;
};
intmain()
{
 RecordPerson1={"usman","younis",{12345,1234567,1},888};
 RecordPerson2,Person3;
 strcpy(Person2.first
_
name,"hamid");
 strcpy(Person2.last
_
name,"ali");
 Person2.identification
_
number=Person1.identification
_
number;
 Person2.height=Person1.height;
 if(Person2.height==Person1.height)
 {
cout<<"Sameheight"<<endl;

cout<<"Person1:"<<endl<<Person1.first
_
name<<""<<
Person1.last
_
name<<"hastheNIC:"<<
Person1.identification
_
number.field1<<"‐"<<
Person1.identification
_
number.field2<<"‐"<<
Person1.identification
_
number.field3<<endl;
cout<<"Person2:"<<endl<<Person2.first
_
name<<""<<
Person2.last
_
name<<"hastheNIC:"<<
Person2.identification
_
number.field1<<"‐"<<
Person2.identification
_
number.field2<<"‐"<<
Person2.identification
_
number.field3<<endl;
 }
 else
cout<<"Notsame"<<endl;
 Person3=Person2;
 cout<<"Person3hasbeenassignedthesamevaluesas"<<
"person2"<<endl;
 cout<<"Person3:"<<endl<<Person3.first
_
name<<""<<
Person3.last
_
name<<"hastheNIC:"<<
Person3.identification
_
number.field1<<"‐"<<
Person3.identification
_
number.field2<<"‐"<<
Person3.identification
_
number.field3<<endl;
 getch();
 return0;
}
docsity.com
pf2

Partial preview of the text

Download C++ Program for Structuring Person's Data with NIC and Height and more Exercises Object Oriented Programming in PDF only on Docsity!

C:\Documents and Settings\Administrator\My ... 2010\Projects\structure\structure\structure.cpp 1 #include #include <conio.h> using namespace std; struct NIC { int field 1 ; int field 2 ; int field 3 ; }; struct Record { char first_name[ 10 ]; char last_name[ 10 ]; NIC identification_number; int height; }; int main() { Record Person 1 = {"usman", "younis", { 12345 , 1234567 , 1 }, 888 }; Record Person 2 , Person 3 ; strcpy(Person 2 .first_name, "hamid"); strcpy(Person 2 .last_name, "ali"); Person 2 .identification_number = Person 1 .identification_number; Person 2 .height = Person 1 .height; if(Person 2 .height == Person 1 .height) { cout<<"Same height"<<endl; cout<<"Person 1 : "<<endl<<Person 1 .first_name<<" "<< Person 1 .last_name<<" has the NIC : "<< Person 1 .identification_number.field 1 <<" ‐ "<< Person 1 .identification_number.field 2 <<" ‐ "<< Person 1 .identification_number.field 3 <<endl; cout<<"Person 2 : "<<endl<<Person 2 .first_name<<" "<< Person 2 .last_name<<" has the NIC : "<< Person 2 .identification_number.field 1 <<" ‐ "<< Person 2 .identification_number.field 2 <<" ‐ "<< Person 2 .identification_number.field 3 <<endl; } else cout<<"Not same"<<endl; Person 3 = Person 2 ; cout<<"Person 3 has been assigned the same values as"<< " person 2 "<<endl; cout<<"Person 3 : "<<endl<<Person 3 .first_name<<" "<< Person 3 .last_name<<" has the NIC : "<< Person 3 .identification_number.field 1 <<" ‐ "<< Person 3 .identification_number.field 2 <<" ‐ "<< Person 3 .identification_number.field 3 <<endl; getch(); return 0 ; }

docsity.com

C:\Documents and Settings\Administrator\My ... 2010\Projects\structure\structure\structure.cpp 2

docsity.com