1 / 23

PRIMITIVE DATA TYPES Integer Floating Point Decimal Boolean Character STRINGS Character Array

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. PRIMITIVE DATA TYPES Integer Floating Point

ruthjbrown
Télécharger la présentation

PRIMITIVE DATA TYPES Integer Floating Point Decimal Boolean Character STRINGS Character Array

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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 • 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 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 IntegerUsing 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 IntegerUsing 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> usingnamespace 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 TypeVC++ .NET #include "stdafx.h" #using <mscorlib.dll> usingnamespace 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. String Concatenation Problem 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>”));

  9. ASCII Code Page

  10. Latin-1 1252 Code Page

  11. UNICODE LAYOUT Basic Plane Figure 1: Figure 1: Unicode encoding layout for the BMP (Plane 0)

  12. Enumeration Types (C++ Example 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; }

  13. Enumeration Types (Java Example)

  14. Program in Disk Virtual Memory

  15. Computing Address of Element In Multidimensional Array

  16. #!/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 pairsprint "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

  17. COBOL RECORD EXAMPLES

  18. Ada RECORD EXAMPLES

  19. C++ UNION TYPES #include <iostream> usingnamespace std; //introduces namespace std int main( void ) { typedefunion _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) ((unsignedchar) byteArray[0])) << " " << ((int) ((unsignedchar) byteArray[1])) << " " << ((int) ((unsignedchar) byteArray[2])) << " " << ((int) ((unsignedchar) byteArray[3])) << " " << ((int) ((unsignedchar) byteArray[4])) << " " << ((int) ((unsignedchar) byteArray[5])) << " " << ((int) ((unsignedchar) byteArray[6])) << " " << ((int) ((unsignedchar) 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

  20. Ada UNION TYPES

More Related