Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

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

This c++ program demonstrates the creation of a struct named 'record' to store a person's first name, last name, national identity card (nic) details, and height. The nic struct consists of three fields: field 1, field 2, and field 3. The main function initializes three record structures and compares their heights. If the heights are equal, it prints their details, including their nic numbers.

Typology: Exercises

2011/2012

Uploaded on 07/31/2012

netu
netu 🇮🇳

4.5

(4)

55 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1C:\DocumentsandSettings\Administrator\My...2010\Projects\structure\structure\structure.cpp
#include<iostream>
#include<conio.h>
usingnamespacestd;
structNIC
{
intfield1;
intfield2;
intfield3;
};
structRecord
{
charfirst
_
name[10];
charlast
_
name[10];
NICidentification
_
number;
intheight;
};
intmain()
{
RecordPerson1={"usman","younis",{12345,1234567,1},888};
RecordPerson2,Person3;
strcpy(Person2.first
_
name,"hamid");
strcpy(Person2.last
_
name,"ali");
Person2.identification
_
number=Person1.identification
_
number;
Person2.height=Person1.height;
if(Person2.height==Person1.height)
{
cout<<"Sameheight"<<endl;

cout<<"Person1:"<<endl<<Person1.first
_
name<<""<<
Person1.last
_
name<<"hastheNIC:"<<
Person1.identification
_
number.field1<<"‐"<<
Person1.identification
_
number.field2<<"‐"<<
Person1.identification
_
number.field3<<endl;
cout<<"Person2:"<<endl<<Person2.first
_
name<<""<<
Person2.last
_
name<<"hastheNIC:"<<
Person2.identification
_
number.field1<<"‐"<<
Person2.identification
_
number.field2<<"‐"<<
Person2.identification
_
number.field3<<endl;
}
else
cout<<"Notsame"<<endl;
Person3=Person2;
cout<<"Person3hasbeenassignedthesamevaluesas"<<
"person2"<<endl;
cout<<"Person3:"<<endl<<Person3.first
_
name<<""<<
Person3.last
_
name<<"hastheNIC:"<<
Person3.identification
_
number.field1<<"‐"<<
Person3.identification
_
number.field2<<"‐"<<
Person3.identification
_
number.field3<<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