SlideShare a Scribd company logo
1 of 23
PRIMITIVE DATA TYPES
-Integer
-Floating Point
-Decimal
-Boolean
-Character
STRINGS
-Character Array
-Class
-String Length
-Static
-Limited Dynamic
-Dynamic
ENUMERATION TYPES
- C++
- Fortran
- Java
SUBRANGE TYPES
ARRAYS
-Indexing
-Flavors
-Static
-Fixed Stack Dynamic
-Stack Dynamic
-Fixed Heap-Dynamic
-Heap Dynamic
-Initalization
-Operations (APL)
-Rectangular/Jagged
-Implementation
-Single Dimensional
-Multi Dimensional
ASSOCIATIVE ARRAYS
RECORD TYPES
UNION TYPES
POINTER/REFERENCE TYPES
-Fundamental Operations
-Problems
-Memory Leak
-Dangling Pointer
-C++
-Java
-Solutions to Pointer Problems
-Tombstone
-Heap Management
-Reference Counter
-Garbage Collection
LECTURE OUTLINE FOR:
CHAPTER 6
DATA TYPES
C++ Weak Typing to Display Integer
int main(void)
{
int theInt = 42;
char* theBytes = &theInt;
cout << “int is: “ << theInt << endl;
cout << “byte values: “
<< ((int) (unsigned char)) theBytes[0] << “ “
<< ((int) (unsigned char)) theBytes[1] << “ “
<< ((int) (unsigned char)) theBytes[2] << “ “
<< ((int) (unsigned char)) theBytes[3] << “ “
<< endl;
}
C++ Weak Typing to Display Integer
Hexadecimal
int main(void)
{
int theInt = 42;
char* theBytes = &theInt;
cout << “int is: “ << theInt << endl;
cout << “byte values: “
<< hex << ((int) (unsigned char)) theBytes[0] << “ “
<< hex << ((int) (unsigned char)) theBytes[1] << “ “
<< hex << ((int) (unsigned char)) theBytes[2] << “ “
<< hex << ((int) (unsigned char)) theBytes[3] << “ “
<< endl;
}
C++ Program to Write/Read Integer
Using Text Files
int main(void)
{
int theInt = 12345678;
ofstream out;
out.open(“temp.txt”);
out << theInt << endl;
out.close();
}
int main(void)
{
int theInt;
ifstream in;
in.open(“temp.txt”);
in >> theInt;
in.close();
.
.
.
}
C++ Program to Write/Read Integer
Using Binary Files
int main(void)
{
int theInt = 12345678;
ofstream out;
out.open(“temp.bin”, ios::binary);
out << theInt << endl;
out.close();
}
int main(void)
{
int theInt;
ifstream in;
in.open(“temp.bin”, ios::binary);
in >> theInt;
in.close();
.
.
.
}
Interest Calculation Using Floating Point Data Type
#include <iostream>
using namespace std;
int main(void)
{
// Credit card balance
double balance = 10.10;
double interest = 0.1;
// Formatting
cout.precision(30);
cout << showpoint;
// Output
cout << "Balance is:t " << balance << endl;
cout << "Interest is:t " << interest << endl;
cout << "New balance is:t " << (balance * (1 + interest)) << endl;
}
Interest Calculation Using Decimal Data Type
VC++ .NET
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
int _tmain()
{
// Credit card balance
Decimal balance = 10.10;
Decimal interest = 0.1;
// Output
Console::WriteLine("Balance is:t {0}",balance.ToString("F30"));
Console::WriteLine("Interest is:t {0}",interest.ToString("F30"));
Console::WriteLine("New Balance is:t {0}",(balance * (1 + interest)).ToString("F30"));
return 0;
}
String* s = new String();
s = s.Concat(s,new String( “<html>”));
s = s.Concat(s,new String( “<body>”));
s = s.Concat(s,new String( “<ul>”));
s = s.Concat(s,new String( “<li> Item One”));
s = s.Concat(s,new String( “<li> Item Two”));
...
s = s.Concat(s,new String( “</ul>”));
s = s.Concat(s,new String( “</body>”));
s = s.Concat(s,new String( “</html>”));
String Concatenation Problem
ASCII Code Page
Latin-1 1252 Code Page
Figure 1: Figure 1: Unicode encoding layout for the BMP (Plane 0)
UNICODE LAYOUT Basic Plane
enum day {Mon, Tue, Wed, Thu, Fri, Sat, Sun};
// Set day of week
day d = Mon;
switch (d)
{
case Mon: cout << “More sleep!” << endl; break;
case Tue: cout << “Close to the hump!” << endl; break;
case Wed: cout << “Hump day!” << endl; break;
case Thu: cout << “Over the hump!” << endl; break;
case Fri: cout << “Yipee! “ << endl; break;
case Sat: cout << “Sweet weekend.” << endl; break;
case Sun: cout << “Rats, almost Monday.” << endl; break;
}
// Set day of week
int d = 0;
switch (d)
{
case 0: cout << “More sleep!” << endl; break;
case 1: cout << “Close to the hump!” << endl; break;
case 2: cout << “Hump day!” << endl; break;
case 3: cout << “Over the hump!” << endl; break;
case 4: cout << “Yipee! “ << endl; break;
case 5: cout << “Sweet weekend.” << endl; break;
case 6: cout << “Rats, almost Monday.” << endl; break;
}
Enumeration Types (C++ Example
public final class Day {
public static final Day MON = new Day();
public static final Day TUE = new Day();
public static final Day WED = new Day();
public static final Day THU = new Day();
public static final Day FRI = new Day();
public static final Day SAT = new Day();
public static final Day SUN = new Day();
private Day() {
// Empty private constructor ensures the only objects of
// this type are the enumerated elements declared above.
}
}
Enumeration Types (Java
Example)
Disk
Program
in
Virtual Memory
Computing Address of Element In
Multidimensional Array
#!/usr/bin/env perl
#
# Welcome to Perl!
#
# To run this program type:
#
# perl AssociativeArrayExample.pl
#
# If the program works... then you've installed
# perl correctly!
#
print "Initializing associative array...n";
%salaries = ("Gary" => 75000, "Perry" => 57000,
"Mary" => 55750, "Cedric" => 47850);
print "Perry's salary is: $salaries{'Perry'}n";
# Iterate and print the key - value pairs
print "Dumping the associative array: n";
foreach my $key (keys %salaries) {
print " value of $key is $salaries{$key}n";
}
print "Deleting Gary from associative array: n";
delete $salaries{"Gary"};
print "Checking for the existance of Gary in array: ";
if (exists $salaries{"Gary"})
{
print "EXISTS!n";
}
else
{
print "DOES NOT EXIST!n";
}
print "Dumping the associative array again: n";
foreach my $key (keys %salaries) {
print " value of $key is $salaries{$key}n";
}
print "Emptying array: n";
%salaries = ();
print "Dumping the associative array again: n";
foreach my $key (keys %salaries) {
print " value of $key is $salaries{$key}n";
}
Perl Program Demonstrating
Associative Arrays
COBOL RECORD EXAMPLES
01 OUTPUT-RECORD.
02 EMPLOYEE-NAME.
05 FIRST PICTURE IS X(20).
05 MIDDLE PICTURE IS X(20).
05 LAST PICTURE IS X(20).
02 EMPLOYEE-NUMBER PICTURE IS 9(10).
02 GROSS-PAY PICTURE IS 999V999.
02 NET-PAY PICTURE IS 999V999.
01 EMPLOYEE-RECORD.
02 EMPLOYEE-NAME.
05 FIRST PICTURE IS X(20).
05 MIDDLE PICTURE IS X(20).
05 LAST PICTURE IS X(20).
02 HOURLY-RATE PICTURE IS 99V99.
02 EMPLOYEE-NUMBER PICTURE IS 9(10).
o Numerals 01, 02, 05 indicate hierarchical structure of
record
o PICTURE – indicates formatting for output
o X(20) – 20 alphanumeric characters
o 99V99 – 4 decimal digits with “.” in middle
o 9(10) – 10 decimal digits
Ada RECORD EXAMPLES
type Employee_Name_Type is record
First : String (1..20);
Middle: String (1..20);
Last: String (1..20);
end record;
type Employee_Record_Type is record
Employee_Name: Employee_Name_Type;
Hourly_Rate: Float;
end record;
Employee_Record: Employee_Record_Type;
C++ UNION TYPES
#include <iostream>
using namespace std; //introduces namespace std
int main( void )
{
typedef union _GenericInput
{
bool theBool;
char theChar;
int theInt;
double theDouble;
} GenericInput;
GenericInput input0;
GenericInput input1;
cout << "Enter a character: ";
cin >> input0.theChar;
cout << "Enter a double: ";
cin >> input1.theDouble;
// You should not be able to assign these two variables
// because they hold different types (char and double)
// but the “free union” capability in C,C++ allows this
// DANGEROUS!!!
input0 = input1;
char *byteArray = (char *) &input1;
cout << hex << ((int) ((unsigned char) byteArray[0])) << " "
<< ((int) ((unsigned char) byteArray[1])) << " "
<< ((int) ((unsigned char) byteArray[2])) << " "
<< ((int) ((unsigned char) byteArray[3])) << " "
<< ((int) ((unsigned char) byteArray[4])) << " "
<< ((int) ((unsigned char) byteArray[5])) << " "
<< ((int) ((unsigned char) byteArray[6])) << " "
<< ((int) ((unsigned char) byteArray[7])) << endl;
cout << "As boolean x[" << input0.theBool << "]" << endl;
cout << "As character [" << input0.theChar << "]" << endl;
cout << "As integer x[" << input0.theInt << "]" << endl;
cout << "As double [" << input0.theDouble << "]" << endl;
return 0;
}
OUTPUT:
Enter a character: a
Enter a double: 10.2
66 66 66 66 66 66 24 40
As boolean x[66]
As character [f]
As integer x[66666666]
As double [10.2]
Press any key to continue
type Shape is (Circle, Triangle, Rectangle);
type Colors is (Red, Green, Blue);
type Figure (Form : Shape) is
record
Filled : Boolean;
Color : Colors;
case Form is
when Circle =>
Diameter : Float;
when Triangle =>
Left_Side : Integer;
Right_Side : Integer;
Angle : Float;
when Rectangle =>
Side_1 : Integer;
Side_2 : Integer;
end case;
end record;
Ada UNION TYPES

More Related Content

Similar to DataTypes.ppt

CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - ReferenceMohammed Sikander
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumpingMomenMostafa
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Troy Miles
 
c++ Lecture 4
c++ Lecture 4c++ Lecture 4
c++ Lecture 4sajidpk92
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxpriestmanmable
 
Analysis of Microsoft Code Contracts
Analysis of Microsoft Code ContractsAnalysis of Microsoft Code Contracts
Analysis of Microsoft Code ContractsPVS-Studio
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfyamew16788
 
Code as data as code.
Code as data as code.Code as data as code.
Code as data as code.Mike Fogus
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsTypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsAlfonso Peletier
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4Abed Bukhari
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questionsSrikanth
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3Srikanth
 
Scala 3camp 2011
Scala   3camp 2011Scala   3camp 2011
Scala 3camp 2011Scalac
 

Similar to DataTypes.ppt (20)

CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - Reference
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
 
c++ Lecture 4
c++ Lecture 4c++ Lecture 4
c++ Lecture 4
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
C++11
C++11C++11
C++11
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
 
Oop1
Oop1Oop1
Oop1
 
C++ practical
C++ practicalC++ practical
C++ practical
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
Analysis of Microsoft Code Contracts
Analysis of Microsoft Code ContractsAnalysis of Microsoft Code Contracts
Analysis of Microsoft Code Contracts
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
 
Code as data as code.
Code as data as code.Code as data as code.
Code as data as code.
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsTypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questions
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3
 
Scala 3camp 2011
Scala   3camp 2011Scala   3camp 2011
Scala 3camp 2011
 

More from RithikRaj25

More from RithikRaj25 (17)

html1.ppt
html1.ppthtml1.ppt
html1.ppt
 
Data
DataData
Data
 
Data
DataData
Data
 
Introduction To Database.ppt
Introduction To Database.pptIntroduction To Database.ppt
Introduction To Database.ppt
 
Data.ppt
Data.pptData.ppt
Data.ppt
 
NoSQL.pptx
NoSQL.pptxNoSQL.pptx
NoSQL.pptx
 
NoSQL
NoSQLNoSQL
NoSQL
 
text classification_NB.ppt
text classification_NB.ppttext classification_NB.ppt
text classification_NB.ppt
 
html1.ppt
html1.ppthtml1.ppt
html1.ppt
 
slide-keras-tf.pptx
slide-keras-tf.pptxslide-keras-tf.pptx
slide-keras-tf.pptx
 
Intro_OpenCV.ppt
Intro_OpenCV.pptIntro_OpenCV.ppt
Intro_OpenCV.ppt
 
lec1b.ppt
lec1b.pptlec1b.ppt
lec1b.ppt
 
PR7.ppt
PR7.pptPR7.ppt
PR7.ppt
 
objectdetect_tutorial.ppt
objectdetect_tutorial.pptobjectdetect_tutorial.ppt
objectdetect_tutorial.ppt
 
14_ReinforcementLearning.pptx
14_ReinforcementLearning.pptx14_ReinforcementLearning.pptx
14_ReinforcementLearning.pptx
 
datamining-lect11.pptx
datamining-lect11.pptxdatamining-lect11.pptx
datamining-lect11.pptx
 
week6a.ppt
week6a.pptweek6a.ppt
week6a.ppt
 

Recently uploaded

9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home ServiceSapana Sha
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样vhwb25kk
 
Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfPredicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfBoston Institute of Analytics
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.natarajan8993
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdfHuman37
 
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degreeyuu sss
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort servicejennyeacort
 
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档208367051
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPramod Kumar Srivastava
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfJohn Sterrett
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFAAndrei Kaleshka
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一F sss
 
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一F La
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfgstagge
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一fhwihughh
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改yuu sss
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDRafezzaman
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 

Recently uploaded (20)

9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
 
Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfPredicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.
 
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf
 
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
 
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdf
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFA
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
 
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdf
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 

DataTypes.ppt

  • 1. PRIMITIVE DATA TYPES -Integer -Floating Point -Decimal -Boolean -Character STRINGS -Character Array -Class -String Length -Static -Limited Dynamic -Dynamic ENUMERATION TYPES - C++ - Fortran - Java SUBRANGE TYPES ARRAYS -Indexing -Flavors -Static -Fixed Stack Dynamic -Stack Dynamic -Fixed Heap-Dynamic -Heap Dynamic -Initalization -Operations (APL) -Rectangular/Jagged -Implementation -Single Dimensional -Multi Dimensional ASSOCIATIVE ARRAYS RECORD TYPES UNION TYPES POINTER/REFERENCE TYPES -Fundamental Operations -Problems -Memory Leak -Dangling Pointer -C++ -Java -Solutions to Pointer Problems -Tombstone -Heap Management -Reference Counter -Garbage Collection LECTURE OUTLINE FOR: CHAPTER 6 DATA TYPES
  • 2. C++ Weak Typing to Display Integer int main(void) { int theInt = 42; char* theBytes = &theInt; cout << “int is: “ << theInt << endl; cout << “byte values: “ << ((int) (unsigned char)) theBytes[0] << “ “ << ((int) (unsigned char)) theBytes[1] << “ “ << ((int) (unsigned char)) theBytes[2] << “ “ << ((int) (unsigned char)) theBytes[3] << “ “ << endl; }
  • 3. C++ Weak Typing to Display Integer Hexadecimal int main(void) { int theInt = 42; char* theBytes = &theInt; cout << “int is: “ << theInt << endl; cout << “byte values: “ << hex << ((int) (unsigned char)) theBytes[0] << “ “ << hex << ((int) (unsigned char)) theBytes[1] << “ “ << hex << ((int) (unsigned char)) theBytes[2] << “ “ << hex << ((int) (unsigned char)) theBytes[3] << “ “ << endl; }
  • 4. C++ Program to Write/Read Integer Using Text Files int main(void) { int theInt = 12345678; ofstream out; out.open(“temp.txt”); out << theInt << endl; out.close(); } int main(void) { int theInt; ifstream in; in.open(“temp.txt”); in >> theInt; in.close(); . . . }
  • 5. C++ Program to Write/Read Integer Using Binary Files int main(void) { int theInt = 12345678; ofstream out; out.open(“temp.bin”, ios::binary); out << theInt << endl; out.close(); } int main(void) { int theInt; ifstream in; in.open(“temp.bin”, ios::binary); in >> theInt; in.close(); . . . }
  • 6. Interest Calculation Using Floating Point Data Type #include <iostream> using namespace std; int main(void) { // Credit card balance double balance = 10.10; double interest = 0.1; // Formatting cout.precision(30); cout << showpoint; // Output cout << "Balance is:t " << balance << endl; cout << "Interest is:t " << interest << endl; cout << "New balance is:t " << (balance * (1 + interest)) << endl; }
  • 7. Interest Calculation Using Decimal Data Type VC++ .NET #include "stdafx.h" #using <mscorlib.dll> using namespace System; int _tmain() { // Credit card balance Decimal balance = 10.10; Decimal interest = 0.1; // Output Console::WriteLine("Balance is:t {0}",balance.ToString("F30")); Console::WriteLine("Interest is:t {0}",interest.ToString("F30")); Console::WriteLine("New Balance is:t {0}",(balance * (1 + interest)).ToString("F30")); return 0; }
  • 8.
  • 9. String* s = new String(); s = s.Concat(s,new String( “<html>”)); s = s.Concat(s,new String( “<body>”)); s = s.Concat(s,new String( “<ul>”)); s = s.Concat(s,new String( “<li> Item One”)); s = s.Concat(s,new String( “<li> Item Two”)); ... s = s.Concat(s,new String( “</ul>”)); s = s.Concat(s,new String( “</body>”)); s = s.Concat(s,new String( “</html>”)); String Concatenation Problem
  • 12.
  • 13.
  • 14. Figure 1: Figure 1: Unicode encoding layout for the BMP (Plane 0) UNICODE LAYOUT Basic Plane
  • 15. enum day {Mon, Tue, Wed, Thu, Fri, Sat, Sun}; // Set day of week day d = Mon; switch (d) { case Mon: cout << “More sleep!” << endl; break; case Tue: cout << “Close to the hump!” << endl; break; case Wed: cout << “Hump day!” << endl; break; case Thu: cout << “Over the hump!” << endl; break; case Fri: cout << “Yipee! “ << endl; break; case Sat: cout << “Sweet weekend.” << endl; break; case Sun: cout << “Rats, almost Monday.” << endl; break; } // Set day of week int d = 0; switch (d) { case 0: cout << “More sleep!” << endl; break; case 1: cout << “Close to the hump!” << endl; break; case 2: cout << “Hump day!” << endl; break; case 3: cout << “Over the hump!” << endl; break; case 4: cout << “Yipee! “ << endl; break; case 5: cout << “Sweet weekend.” << endl; break; case 6: cout << “Rats, almost Monday.” << endl; break; } Enumeration Types (C++ Example
  • 16. public final class Day { public static final Day MON = new Day(); public static final Day TUE = new Day(); public static final Day WED = new Day(); public static final Day THU = new Day(); public static final Day FRI = new Day(); public static final Day SAT = new Day(); public static final Day SUN = new Day(); private Day() { // Empty private constructor ensures the only objects of // this type are the enumerated elements declared above. } } Enumeration Types (Java Example)
  • 18. Computing Address of Element In Multidimensional Array
  • 19. #!/usr/bin/env perl # # Welcome to Perl! # # To run this program type: # # perl AssociativeArrayExample.pl # # If the program works... then you've installed # perl correctly! # print "Initializing associative array...n"; %salaries = ("Gary" => 75000, "Perry" => 57000, "Mary" => 55750, "Cedric" => 47850); print "Perry's salary is: $salaries{'Perry'}n"; # Iterate and print the key - value pairs print "Dumping the associative array: n"; foreach my $key (keys %salaries) { print " value of $key is $salaries{$key}n"; } print "Deleting Gary from associative array: n"; delete $salaries{"Gary"}; print "Checking for the existance of Gary in array: "; if (exists $salaries{"Gary"}) { print "EXISTS!n"; } else { print "DOES NOT EXIST!n"; } print "Dumping the associative array again: n"; foreach my $key (keys %salaries) { print " value of $key is $salaries{$key}n"; } print "Emptying array: n"; %salaries = (); print "Dumping the associative array again: n"; foreach my $key (keys %salaries) { print " value of $key is $salaries{$key}n"; } Perl Program Demonstrating Associative Arrays
  • 20. COBOL RECORD EXAMPLES 01 OUTPUT-RECORD. 02 EMPLOYEE-NAME. 05 FIRST PICTURE IS X(20). 05 MIDDLE PICTURE IS X(20). 05 LAST PICTURE IS X(20). 02 EMPLOYEE-NUMBER PICTURE IS 9(10). 02 GROSS-PAY PICTURE IS 999V999. 02 NET-PAY PICTURE IS 999V999. 01 EMPLOYEE-RECORD. 02 EMPLOYEE-NAME. 05 FIRST PICTURE IS X(20). 05 MIDDLE PICTURE IS X(20). 05 LAST PICTURE IS X(20). 02 HOURLY-RATE PICTURE IS 99V99. 02 EMPLOYEE-NUMBER PICTURE IS 9(10). o Numerals 01, 02, 05 indicate hierarchical structure of record o PICTURE – indicates formatting for output o X(20) – 20 alphanumeric characters o 99V99 – 4 decimal digits with “.” in middle o 9(10) – 10 decimal digits
  • 21. Ada RECORD EXAMPLES type Employee_Name_Type is record First : String (1..20); Middle: String (1..20); Last: String (1..20); end record; type Employee_Record_Type is record Employee_Name: Employee_Name_Type; Hourly_Rate: Float; end record; Employee_Record: Employee_Record_Type;
  • 22. C++ UNION TYPES #include <iostream> using namespace std; //introduces namespace std int main( void ) { typedef union _GenericInput { bool theBool; char theChar; int theInt; double theDouble; } GenericInput; GenericInput input0; GenericInput input1; cout << "Enter a character: "; cin >> input0.theChar; cout << "Enter a double: "; cin >> input1.theDouble; // You should not be able to assign these two variables // because they hold different types (char and double) // but the “free union” capability in C,C++ allows this // DANGEROUS!!! input0 = input1; char *byteArray = (char *) &input1; cout << hex << ((int) ((unsigned char) byteArray[0])) << " " << ((int) ((unsigned char) byteArray[1])) << " " << ((int) ((unsigned char) byteArray[2])) << " " << ((int) ((unsigned char) byteArray[3])) << " " << ((int) ((unsigned char) byteArray[4])) << " " << ((int) ((unsigned char) byteArray[5])) << " " << ((int) ((unsigned char) byteArray[6])) << " " << ((int) ((unsigned char) byteArray[7])) << endl; cout << "As boolean x[" << input0.theBool << "]" << endl; cout << "As character [" << input0.theChar << "]" << endl; cout << "As integer x[" << input0.theInt << "]" << endl; cout << "As double [" << input0.theDouble << "]" << endl; return 0; } OUTPUT: Enter a character: a Enter a double: 10.2 66 66 66 66 66 66 24 40 As boolean x[66] As character [f] As integer x[66666666] As double [10.2] Press any key to continue
  • 23. type Shape is (Circle, Triangle, Rectangle); type Colors is (Red, Green, Blue); type Figure (Form : Shape) is record Filled : Boolean; Color : Colors; case Form is when Circle => Diameter : Float; when Triangle => Left_Side : Integer; Right_Side : Integer; Angle : Float; when Rectangle => Side_1 : Integer; Side_2 : Integer; end case; end record; Ada UNION TYPES