Image Steganalysis Image Steganography

Size: px
Start display at page:

Download "Image Steganalysis Image Steganography"

Transcription

1 //Joshua Tracy #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv2/opencv.hpp" #include <stdlib.h> #include <iostream> #include <stdint.h> #include <time.h> using namespace cv; int main(int argc, char* argv[]) Mat hidden = imread(argv[1]); int w1, h1; w1 = hidden.cols; h1 = hidden.rows; Image Steganalysis //******LSB ENhancment******************** for (int i = 0; i < h1; i++) for (int j = 0; j < w1*3 ; j++) int lsb = hidden.at<char>(i, j); lsb = lsb & 1; if (lsb) hidden.at<char>(i, j) = 255; hidden.at<char>(i, j) = 0; imwrite(argv[2], hidden); return 0; //Joshua Tracy #include <opencv2/core/core.hpp> #include "opencv2/opencv.hpp" #include <opencv2/highgui/highgui.hpp> #include <iostream> #include <stdint.h> using namespace cv; using namespace std; char ExtractChar(Mat coverimage, int i, int j) Image Steganography

2 int bit; int red = coverimage.at<char>(i, j); int green = coverimage.at<char>(i, j + 1); int blue = coverimage.at<char>(i, j + 2); j += 3; if (j / 3 == coverimage.cols) int red2 = coverimage.at<char>(i, j); int green2 = coverimage.at<char>(i, j + 1); int blue2 = coverimage.at<char>(i, j + 2); // convert the two pixels to a character unsigned int T = 0; T += (red & 1); T += (2 * (green & 1)); T += (4 * (blue & 1)); bit = blue & 2; if (bit > 0) bit = 1; bit = 0; T += (8 * bit); T += (16 * (red2 & 1)); T += (32 * (green2 & 1)); T += (64 * (blue2 & 1)); bit = blue2 & 2; if (bit > 0) bit = 1; bit = 0; T += (128 * bit); char c = (char)t; return c; void encode(char* file, char* image, char* outputfile) Mat coverimage = imread(image, CV_LOAD_IMAGE_UNCHANGED); //cvtcolor(coverimage, coverimage, CV_RGBA2BGRA); if (!coverimage.data) cout << "Could not read one of the immages " << endl; int MaxNumberOfPixels = coverimage.rows * coverimage.cols; int MaxCharsToEncode = (int)(0.5 * MaxNumberOfPixels); int NumberOfCharsToEncode; int FileNameSize = strlen(file) + 1; char * FileName = new char[filenamesize]; strcpy(filename, file);

3 int filesize = 0; char* StegoIdentifierString = "JTstego"; FILE* fp; fp = fopen(file, "rb"); if (!fp) cout << "Error: unable to read file " << file << " for text input!" << endl; NumberOfCharsToEncode = FileNameSize + strlen(stegoidentifierstring) + 2 // indicate length of filename + 4; // indicate length of data unsigned char *CharsToEncode = new unsigned char[numberofcharstoencode]; if (NumberOfCharsToEncode > MaxCharsToEncode) cout << "Error: File is too small to even encode file information!\n" << " Terminating encoding.\n"; while (!feof(fp)) char c; fread(&c, 1, 1, fp); filesize++; filesize--; MaxCharsToEncode -= NumberOfCharsToEncode; if (filesize > MaxCharsToEncode) filesize = MaxCharsToEncode; cout << "Warning: Input file exceeds encoding capacity of the image\n" << " File will be truncated.\n"; fclose(fp); // create this "file header" string int k = 0; // this part gives the length of the filename while (k < strlen(stegoidentifierstring)) CharsToEncode[k] = StegoIdentifierString[k]; k++;

4 int TempInt = FileNameSize % 256; CharsToEncode[k] = (unsigned char)tempint; k++; TempInt = FileNameSize - TempInt; if (TempInt < 0) TempInt = 0; TempInt = TempInt / 256; CharsToEncode[k] = (unsigned char)tempint; k++; // this part hides the filename int j = 0; while (j < FileNameSize) CharsToEncode[k] = FileName[j]; k++; j++; // this part gives the length of the hidden data int TempIntOriginal = filesize; TempInt = filesize % 256; CharsToEncode[k] = (unsigned char)tempint; k++; TempIntOriginal -= TempInt; if (TempIntOriginal > 0) TempInt = TempIntOriginal % 65536; CharsToEncode[k] = (unsigned char)(tempint / 256); k++; TempIntOriginal -= TempInt;// *256; CharsToEncode[k] = 0; k++; if (TempIntOriginal > 0) TempInt = TempIntOriginal % ; CharsToEncode[k] = (unsigned char)(tempint / 65536); k++; TempIntOriginal -= TempInt;// *65536; CharsToEncode[k] = 0; k++; if (TempIntOriginal > 0) TempInt = TempIntOriginal % ; CharsToEncode[k] = (unsigned char)(tempint / ); k++; TempIntOriginal -= TempInt;// * ;

5 CharsToEncode[k] = 0; k++; k = 0; int i = 0; j = 0; fp = fopen(file, "rb"); while (!feof(fp) && k < NumberOfCharsToEncode) // decompose the character unsigned int T = (unsigned int)charstoencode[k]; int R1 = T % 2; T = (T - R1) / 2; int G1 = T % 2; T = (T - G1) / 2; int B1 = T % 2; T = (T - B1) / 2; int A1 = T % 2; T = (T - A1) / 2; int R2 = T % 2; T = (T - R2) / 2; int G2 = T % 2; T = (T - G2) / 2; int B2 = T % 2; T = (T - B2) / 2; int A2 = T % 2; T = (T - A2) / 2; int red = coverimage.at<char>(i, j); int green = coverimage.at<char>(i, j+1); int blue = coverimage.at<char>(i, j+2); red = red -(red &1) + R1; green = green - (green & 1) + G1; blue = blue - (blue & 3) + B1 + (A1*2); coverimage.at<char>(i, j) = red; coverimage.at<char>(i, j + 1) = green; coverimage.at<char>(i, j + 2) = blue ; j+=3; if (j/3 == coverimage.cols) red = coverimage.at<char>(i, j); green = coverimage.at<char>(i, j + 1);

6 blue = coverimage.at<char>(i, j + 2); red = red - (red & 1) + R2; green = green - (green & 1) + G2; blue = blue - (blue & 3) + B2 + (A2 * 2); coverimage.at<char>(i, j) = red; coverimage.at<char>(i, j + 1) = green; coverimage.at<char>(i, j + 2) = blue; j+=3; k++; if (j/3 == coverimage.cols) // encode the actual data k = 0; while (!feof(fp) && k < 6 * filesize) char c; fread(&c, 1, 1, fp); // decompose the character unsigned int T = (unsigned int)c; int R1 = T % 2; T = (T - R1) / 2; int G1 = T % 2; T = (T - G1) / 2; int B1 = T % 2; T = (T - B1) / 2; int A1 = T % 2; T = (T - A1) / 2; int R2 = T % 2; T = (T - R2) / 2; int G2 = T % 2; T = (T - G2) / 2; int B2 = T % 2; T = (T - B2) / 2; int A2 = T % 2; T = (T - A2) / 2; int red = coverimage.at<char>(i, j); int green = coverimage.at<char>(i, j + 1); int blue = coverimage.at<char>(i, j + 2); red = red - (red & 1) + R1; green = green - (green & 1) + G1;

7 blue = blue - (blue & 3) + B1 + (A1 * 2); coverimage.at<char>(i, j) = red; coverimage.at<char>(i, j + 1) = green; coverimage.at<char>(i, j + 2) = blue; j += 3; if (j / 3 == coverimage.cols) red = coverimage.at<char>(i, j); green = coverimage.at<char>(i, j + 1); blue = coverimage.at<char>(i, j + 2); red = red - (red & 1) + R2; green = green - (green & 1) + G2; blue = blue - (blue & 3) + B2 + (A2 * 2); coverimage.at<char>(i, j) = red; coverimage.at<char>(i, j + 1) = green; coverimage.at<char>(i, j + 2) = blue; j += 3; k++; if (j / 3 == coverimage.cols) fclose(fp); imwrite(outputfile, coverimage); void decode(char* image) Mat coverimage = imread(image, CV_LOAD_IMAGE_UNCHANGED); if (!coverimage.data) cout << "Could not read the image " << endl; char* StegoIdentifierString = "JTstego"; char* ComparisonString = new char[strlen(stegoidentifierstring) + 1]; int i = 0; int j = 0; int k = 0; while (k < strlen(stegoidentifierstring)) ComparisonString[k] = ExtractChar(coverimage, i, j); while (j/3 >= coverimage.cols) j =0; i++;

8 k++; ComparisonString[k] = '\0'; if (strcmp(stegoidentifierstring, ComparisonString)) cout << "Error: No (compatible) hidden data found in image!\n"; // get the next two characters to determine file size unsigned char C1 = (unsigned char)extractchar(coverimage, i, j); unsigned char C2 = (unsigned char)extractchar(coverimage, i, j); int FileNameSize = C * C2; char* FileName = new char[filenamesize]; // read the filename k = 0; while (k < FileNameSize) FileName[k] = ExtractChar(coverimage, i, j); k++; FileName[k] = '\0'; // find the actual data size C1 = (unsigned char)extractchar(coverimage, i, j);

9 C2 = (unsigned char)extractchar(coverimage, i, j); unsigned char C3 = (unsigned char)extractchar(coverimage, i, j); unsigned char C4 = (unsigned char)extractchar(coverimage, i, j); int FileSize = C1 + (256 * C2) + (65536 * C3) + ( * C4); int NumberOfCharsToEncode = FileNameSize strlen(stegoidentifierstring); if (FileSize == 0 FileNameSize == 0 NumberOfCharsToEncode == 0) cout << "No hiddent data detected. Exiting... " << endl; cout << "Hidden data detected! Outputting to file " << FileName << "... " << endl; FILE* fp; fp = fopen(filename, "wb"); if (!fp) cout << "Error: Unable to open file " << FileName << " for output!\n"; int MaxNumberOfPixels = coverimage.cols * coverimage.rows; k = 0; i = 0; j = 0; // set the starting pixel to skip the internal header j = 6 * NumberOfCharsToEncode;

10 while (k < 6 * FileSize) // read the two pixels int bit; int red = coverimage.at<char>(i, j); int green = coverimage.at<char>(i, j + 1); int blue = coverimage.at<char>(i, j + 2); j += 3; k++; if (j / 3 == coverimage.cols) int red2 = coverimage.at<char>(i, j); int green2 = coverimage.at<char>(i, j + 1); int blue2 = coverimage.at<char>(i, j + 2); j += 3; k++; if (j / 3 == coverimage.cols) // convert the two pixels to a character unsigned int T = 0; T += (red & 1); T += (2 * (green & 1)); T += (4 * (blue & 1)); bit = blue & 2; if (bit > 0) bit = 1; bit = 0; T += (8 * bit); T += (16 * (red2 & 1)); T += (32 * (green2 & 1)); T += (64 * (blue2 & 1)); bit = blue2 & 2; if (bit > 0) bit = 1; bit = 0; T += (128 * bit); char c = (char)t; fwrite(&c, 1, 1, fp); fclose(fp);

11 int main(int argc, char* argv[]) if (*argv[1]=='e'&&argc==5) encode(argv[2], argv[3], argv[4]); if (*argv[1] == 'd'&&argc == 3) decode(argv[2]); //waitkey(0); return 0;

OpenCV. OpenCV Tutorials OpenCV User Guide OpenCV API Reference. docs.opencv.org. F. Xabier Albizuri

OpenCV. OpenCV Tutorials OpenCV User Guide OpenCV API Reference. docs.opencv.org. F. Xabier Albizuri OpenCV OpenCV Tutorials OpenCV User Guide OpenCV API Reference docs.opencv.org F. Xabier Albizuri - 2014 OpenCV Tutorials OpenCV Tutorials: Introduction to OpenCV The Core Functionality (core module) Image

More information

Computer and Machine Vision

Computer and Machine Vision Computer and Machine Vision Lecture Week 12 Part-1 Additional Programming Considerations March 29, 2014 Sam Siewert Outline of Week 12 Computer Vision APIs and Languages Alternatives to C++ and OpenCV

More information

typedef Labeling<unsigned char,short> LabelingBS; typedef Labeling<unsigned char,short>::regioninfo RegionInfoBS;

typedef Labeling<unsigned char,short> LabelingBS; typedef Labeling<unsigned char,short>::regioninfo RegionInfoBS; 2005 7 19 1 ( ) Labeling 2 C++ STL(Standard Template Library) g++ (GCC) 3.3.2 3 3.1 Labeling SrcT DstT SrcT: unsigned char, shoft DstT: short typedef 1. unsigned char, short typedef Labeling

More information

Multimedia Retrieval Exercise Course 2 Basic Knowledge about Images in OpenCV

Multimedia Retrieval Exercise Course 2 Basic Knowledge about Images in OpenCV Multimedia Retrieval Exercise Course 2 Basic Knowledge about Images in OpenCV Kimiaki Shirahama, D.E. Research Group for Pattern Recognition Institute for Vision and Graphics University of Siegen, Germany

More information

Linked List using a Sentinel

Linked List using a Sentinel Linked List using a Sentinel Linked List.h / Linked List.h Using a sentinel for search Created by Enoch Hwang on 2/1/10. Copyright 2010 La Sierra University. All rights reserved. / #include

More information

Streams. Rupesh Nasre.

Streams. Rupesh Nasre. Streams Rupesh Nasre. OOAIA January 2018 I/O Input stream istream cin Defaults to keyboard / stdin Output stream ostream cout std::string name; std::cout > name; std::cout

More information

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name:  ID: Page 1 of 10 Name: Email ID: You MUST write your name and e-mail ID on EACH page and bubble in your userid at the bottom of EACH page including this page and page 10. If you do not do this, you will receive

More information

Physics 234: Computational Physics

Physics 234: Computational Physics Physics 234: Computational Physics In-class Midterm Exam Friday, February 12, 2010 Student s Name: Fill-in-the-blank and multiple choice questions (20 points) Mark your answers on the exam sheet in blue

More information

A Quick Look at C for C++ Programmers

A Quick Look at C for C++ Programmers COMP 40: Machine Structure and Assembly Language Programming (Fall 2017) A Quick Look at C for C++ Programmers Noah Mendelsohn (with updates by Mark Sheldon) Tufts University Email: noah@cs.tufts.edu Web:

More information

CS2141 Software Development using C/C++ C++ Basics

CS2141 Software Development using C/C++ C++ Basics CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short

More information

s s tr t r s t st t t rt r t s r 2 st t t t s 2 r r r t t r r t t t s r t t s ss r2 r t t s s t t t r s q r t r t rs

s s tr t r s t st t t rt r t s r 2 st t t t s 2 r r r t t r r t t t s r t t s ss r2 r t t s s t t t r s q r t r t rs Pr t t r 2 t t t r str t r s t s r t s t 1 r s t r 2 t q s t r 2 r rs t r t s r s s s t t t 2 s t r t t t 1 st t r t s t r 2 s 2 r q r ts t st s t s 2 t s r r t2 s r t2 r t t2 t t s t t r st st r t s t

More information

vector<process*> Delete(vector<process*> DeleteQ, int ID); vector<process*> DeleteW(vector<process*> DeleteWQ, int IDW);

vector<process*> Delete(vector<process*> DeleteQ, int ID); vector<process*> DeleteW(vector<process*> DeleteWQ, int IDW); Matt Ramsay & Robert Brown CS 470 Process Management Project 2/15/02 File: main.cpp Uncommented Code: /*********************************** ** Matthew Ramsay Robert Brown ** ** CS470 Dr. Deborah Hwang **

More information

Reading from and Writing to Files. Files (3.12) Steps to Using Files. Section 3.12 & 13.1 & Data stored in variables is temporary

Reading from and Writing to Files. Files (3.12) Steps to Using Files. Section 3.12 & 13.1 & Data stored in variables is temporary Reading from and Writing to Files Section 3.12 & 13.1 & 13.5 11/3/08 CS150 Introduction to Computer Science 1 1 Files (3.12) Data stored in variables is temporary We will learn how to write programs that

More information

Comparing Different Visual Motion Detection Algorithms

Comparing Different Visual Motion Detection Algorithms Comparing Different Visual Motion Detection Algorithms New Mexico Supercomputing Challenge Final Report April 1, 2014 Team: 143 School of Dreams Academy Team Members: Albert Reed Zack Daniels Chloe Grubb

More information

C++ Namespaces, Exceptions

C++ Namespaces, Exceptions C++ Namespaces, Exceptions CSci 588: Data Structures, Algorithms and Software Design http://www.cplusplus.com/doc/tutorial/namespaces/ http://www.cplusplus.com/doc/tutorial/exceptions/ http://www.cplusplus.com/doc/tutorial/typecasting/

More information

Unit Testing. Contents. Steven Zeil. July 22, Types of Testing 2. 2 Unit Testing Scaffolding Drivers Stubs...

Unit Testing. Contents. Steven Zeil. July 22, Types of Testing 2. 2 Unit Testing Scaffolding Drivers Stubs... Steven Zeil July 22, 2013 Contents 1 Types of Testing 2 2 6 2.1 Scaffolding................. 7 2.1.1 Drivers............... 7 2.1.2 Stubs................ 13 3 Integration Testing 17 1 1 Types of Testing

More information

Unit Testing. Steven Zeil. July 22, Types of Testing 2. 2 Unit Testing Scaffolding Drivers Stubs...

Unit Testing. Steven Zeil. July 22, Types of Testing 2. 2 Unit Testing Scaffolding Drivers Stubs... Steven Zeil July 22, 2013 Contents 1 Types of Testing 2 2 Unit Testing 4 2.1 Scaffolding............ 4 2.1.1 Drivers.......... 4 2.1.2 Stubs........... 9 3 Integration Testing 12 1 1 Types of Testing Testing

More information

Data Structures. Lecture 04 Sohail Aslam AL 1

Data Structures. Lecture 04 Sohail Aslam AL 1 Data Structures Lecture 04 Sohail Aslam 1 C++ Code for Linked List // position current before the first // list element void start() { lastcurrentnode = headnode; currentnode = headnode; }; 2 C++ Code

More information

ECE 661: Homework #3

ECE 661: Homework #3 ECE 661: Homework #3 September 18, 2012 Professor Kak Albert Parra Pozo Contents Method Outline............................................... 2 Two-Step Method.............................................

More information

CSE au Midterm Exam Nov. 2, 2018 Sample Solution

CSE au Midterm Exam Nov. 2, 2018 Sample Solution Question 1. (16 points) Build tools and make. We re building a C++ software back-end prototype for a new food web site. So far, we ve got the following source files with the code for two main programs

More information

OpenCV. Basics. Department of Electrical Engineering and Computer Science

OpenCV. Basics. Department of Electrical Engineering and Computer Science OpenCV Basics 1 OpenCV header file OpenCV namespace OpenCV basic structures Primitive data types Point_ Size_ Vec Scalar_ Mat Basics 2 OpenCV Header File #include .hpp is a convention

More information

Programmazione. Prof. Marco Bertini

Programmazione. Prof. Marco Bertini Programmazione Prof. Marco Bertini marco.bertini@unifi.it http://www.micc.unifi.it/bertini/ Hello world : a review Some differences between C and C++ Let s review some differences between C and C++ looking

More information

C++ Scope Resolution Operator ::

C++ Scope Resolution Operator :: C++ Scope Resolution Operator :: C++The :: (scope resolution) operator is used to qualify hidden names so that you can still use them. You can use the unary scope operator if a namespace scope or global

More information

Program Organization and Comments

Program Organization and Comments C / C++ PROGRAMMING Program Organization and Comments Copyright 2013 Dan McElroy Programming Organization The layout of a program should be fairly straight forward and simple. Although it may just look

More information

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8 Today... Java basics S. Bowers 1 of 8 Java main method (cont.) In Java, main looks like this: public class HelloWorld { public static void main(string[] args) { System.out.println("Hello World!"); Q: How

More information

Lab Instructor : Jean Lai

Lab Instructor : Jean Lai Lab Instructor : Jean Lai Group related statements to perform a specific task. Structure the program (No duplicate codes!) Must be declared before used. Can be invoked (called) as any number of times.

More information

- It computes the Standard Deviation by calculating the difference of each channel (R,G,B and A) of a pixel.

- It computes the Standard Deviation by calculating the difference of each channel (R,G,B and A) of a pixel. Standard Deviation: It is common to find comparison of two bitmaps in Image Processing Development. Comparison of two bitmaps means how each pixel of image1 is different from corresponding pixel of image2

More information

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi Modern C++ for Computer Vision and Image Processing Igor Bogoslavskyi Outline Generic programming Template functions Template classes Iterators Error handling Program input parameters OpenCV cv::mat cv::mat

More information

M.CS201 Programming language

M.CS201 Programming language Power Engineering School M.CS201 Programming language Lecture 16 Lecturer: Prof. Dr. T.Uranchimeg Agenda Opening a File Errors with open files Writing and Reading File Data Formatted File Input Direct

More information

Praktikum: 4. Content of today s lecture. Content of today s lecture. Manfred Grove Houxiang Zhang. Program introduction. Program introduction

Praktikum: 4. Content of today s lecture. Content of today s lecture. Manfred Grove Houxiang Zhang. Program introduction. Program introduction 18.272 Praktikum: 4 Telebot system environment Lecturers Manfred Grove Houxiang Zhang TAMS, Department t of Informatics, Germany @Tams group Institute TAMS s http://tams-www.informatik.uni-hamburg.de/hzhang

More information

Program template-smart-pointers-again.cc

Program template-smart-pointers-again.cc 1 // Illustrate the smart pointer approach using Templates 2 // George F. Riley, Georgia Tech, Spring 2012 3 // This is nearly identical to the earlier handout on smart pointers 4 // but uses a different

More information

redis-c-examples Documentation

redis-c-examples Documentation redis-c-examples Documentation Release 0.1.0 Vladimir Botka Mar 05, 2018 Contents: 1 Introduction 1 2 Examples 3 2.1 Create frequency graph from a log.................................... 3 2.2 List 10

More information

Lab 1: First Steps in C++ - Eclipse

Lab 1: First Steps in C++ - Eclipse Lab 1: First Steps in C++ - Eclipse Step Zero: Select workspace 1. Upon launching eclipse, we are ask to chose a workspace: 2. We select a new workspace directory (e.g., C:\Courses ): 3. We accept the

More information

Darshan Institute of Engineering & Technology for Diploma Studies Unit 6

Darshan Institute of Engineering & Technology for Diploma Studies Unit 6 1. What is File management? In real life, we want to store data permanently so that later on we can retrieve it and reuse it. A file is a collection of bytes stored on a secondary storage device like hard

More information

Representation of image data

Representation of image data Representation of image data Images (e.g. digital photos) consist of a rectanglular array of discrete picture elements called pixels. An image consisting of 200 pixels rows of 300 pixels per row contains

More information

Introduction to C++ 2. A Simple C++ Program. A C++ program consists of: a set of data & function definitions, and the main function (or driver)

Introduction to C++ 2. A Simple C++ Program. A C++ program consists of: a set of data & function definitions, and the main function (or driver) Introduction to C++ 1. General C++ is an Object oriented extension of C which was derived from B (BCPL) Developed by Bjarne Stroustrup (AT&T Bell Labs) in early 1980 s 2. A Simple C++ Program A C++ program

More information

Manfred Grove Houxiang Zhang

Manfred Grove Houxiang Zhang Praktik kum: 4 Telebot system environment Lecturers Manfred Grove Houxiang Zhang TAMS, Department of Informatics, Germany @Tams group Institute TAMS s http://tams-www.informatik.uni-hamburg.de/hzhang 1

More information

Strings and Stream I/O

Strings and Stream I/O Strings and Stream I/O C Strings In addition to the string class, C++ also supports old-style C strings In C, strings are stored as null-terminated character arrays str1 char * str1 = "What is your name?

More information

Problem Solving: Storyboards for User Interaction

Problem Solving: Storyboards for User Interaction Topic 6 1. The while loop 2. Problem solving: hand-tracing 3. The for loop 4. The do loop 5. Processing input 6. Problem solving: storyboards 7. Common loop algorithms 8. Nested loops 9. Problem solving:

More information

PROGRAMMING IN C++ CVIČENÍ

PROGRAMMING IN C++ CVIČENÍ PROGRAMMING IN C++ CVIČENÍ INFORMACE Michal Brabec http://www.ksi.mff.cuni.cz/ http://www.ksi.mff.cuni.cz/~brabec/ brabec@ksi.mff.cuni.cz gmichal.brabec@gmail.com REQUIREMENTS FOR COURSE CREDIT Basic requirements

More information

Program template-smart-pointers.cc

Program template-smart-pointers.cc 1 // Illustrate the smart pointer approach using Templates 2 // George F. Riley, Georgia Tech, Spring 2012 3 4 #include 5 #include 6 7 using namespace std; 8 9 // The Ptr class contains

More information

Unified Modeling Language a case study

Unified Modeling Language a case study Unified Modeling Language a case study 1 an online phone book use case diagram encapsulating a file 2 Command Line Arguments arguments of main arrays of strings 3 Class Definition the filesphonebook.h

More information

Programming. C++ Basics

Programming. C++ Basics Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++

More information

C FILE Type. Basic I/O in C. Accessing a stream requires a pointer variable of type FILE.

C FILE Type. Basic I/O in C. Accessing a stream requires a pointer variable of type FILE. C FILE Type Accessing a stream requires a pointer variable of type FILE. 1 C provides three standard streams, which require no special preparation other than the necessary include directive: stdin standard

More information

Lab 8. Follow along with your TA as they demo GDB. Make sure you understand all of the commands, how and when to use them.

Lab 8. Follow along with your TA as they demo GDB. Make sure you understand all of the commands, how and when to use them. Lab 8 Each lab will begin with a recap of last lab and a brief demonstration by the TAs for the core concepts examined in this lab. As such, this document will not serve to tell you everything the TAs

More information

Program threaded-fft-mutex.cc

Program threaded-fft-mutex.cc 1 // 2D FFT Using threads 2 // George F. Riley, Georgia Tech, Fall 2009 3 // This illustrates how a mutex would be implemented (both a "buggy" version 4 // and a good one). 5 6 #include 7 8

More information

Matt Ramsay CS 375 EXAM 2 Part 1

Matt Ramsay CS 375 EXAM 2 Part 1 Matt Ramsay CS 375 EXAM 2 Part 1 Output: csserver:/home/mr56/cs375/exam2 > parent 1 75000 Multiples of 3 between 3 and 15000 add to 37507500 This total written to /home/mr56/tmp/file8771.out Multiples

More information

Sample Final Exam. 1) (24 points) Show what is printed by the following segments of code (assume all appropriate header files, etc.

Sample Final Exam. 1) (24 points) Show what is printed by the following segments of code (assume all appropriate header files, etc. Name: Sample Final Exam 1) (24 points) Show what is printed by the following segments of code (assume all appropriate header files, etc. are included): a) int start = 10, end = 21; while (start < end &&

More information

CS302 - Data Structures using C++

CS302 - Data Structures using C++ CS302 - Data Structures using C++ Topic: Kostas Alexis Introduction to the problem The Towers of Hanoi is a mathematical puzzle where one has three pegs and n disks and the goal is to move the entire stack

More information

Java Basic Syntax. Java vs C++ Wojciech Frohmberg / OOP Laboratory. Poznan University of Technology

Java Basic Syntax. Java vs C++ Wojciech Frohmberg / OOP Laboratory. Poznan University of Technology Java vs C++ 1 1 Department of Computer Science Poznan University of Technology 2012.10.07 / OOP Laboratory Outline 1 2 3 Outline 1 2 3 Outline 1 2 3 Tabular comparizon C++ Java Paradigm Procedural/Object-oriented

More information

BSc (Hons) Computer Science. with Network Security. Examinations for / Semester1

BSc (Hons) Computer Science. with Network Security. Examinations for / Semester1 BSc (Hons) Computer Science with Network Security Cohort: BCNS/15B/FT Examinations for 2015-2016 / Semester1 MODULE: PROGRAMMING CONCEPT MODULE CODE: PROG 1115C Duration: 3 Hours Instructions to Candidates:

More information

C FILE Type. Basic I/O in C. Accessing a stream requires a pointer of type FILE.

C FILE Type. Basic I/O in C. Accessing a stream requires a pointer of type FILE. C FILE Type Accessing a stream requires a pointer of type FILE. 1 C provides three standard streams, which require no special preparation other than the necessary include directive: stdin standard input

More information

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references The main body and cout 2 C++ IS AN OO EXTENSION OF

More information

CSC209H Lecture 3. Dan Zingaro. January 21, 2015

CSC209H Lecture 3. Dan Zingaro. January 21, 2015 CSC209H Lecture 3 Dan Zingaro January 21, 2015 Streams (King 22.1) Stream: source of input or destination for output We access a stream through a file pointer (FILE *) Three streams are available without

More information

Fundamentals of Programming. Lecture 19 Hamed Rasifard

Fundamentals of Programming. Lecture 19 Hamed Rasifard Fundamentals of Programming Lecture 19 Hamed Rasifard 1 Outline C++ Object-Oriented Programming Class 2 C++ C++ began as an expanded version of C. C++ improves on many of C s features and provides object-oriented-programming

More information

primitive arrays v. vectors (1)

primitive arrays v. vectors (1) Arrays 1 primitive arrays v. vectors (1) 2 int a[10]; allocate new, 10 elements vector v(10); // or: vector v; v.resize(10); primitive arrays v. vectors (1) 2 int a[10]; allocate new, 10 elements

More information

Increment and the While. Class 15

Increment and the While. Class 15 Increment and the While Class 15 Increment and Decrement Operators Increment and Decrement Increase or decrease a value by one, respectively. the most common operation in all of programming is to increment

More information

The fopen command can open an external file in C language. If the file is exist, the file pointer is not NULL. Otherwise, the file pointer is NULL.

The fopen command can open an external file in C language. If the file is exist, the file pointer is not NULL. Otherwise, the file pointer is NULL. File Input / Output File open FILE *fopen( filename, mode ); The fopen command can open an external file in C language. If the file is exist, the file pointer is not NULL. Otherwise, the file pointer is

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 10 October 1, 2018 CPSC 427, Lecture 10, October 1, 2018 1/20 Brackets Example (continued from lecture 8) Stack class Brackets class Main

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 7 September 21, 2016 CPSC 427, Lecture 7 1/21 Brackets Example (continued) Storage Management CPSC 427, Lecture 7 2/21 Brackets Example

More information

#include <stdlib.h> #include <stdio.h> #include "opencv2/opencv.hpp" #include <vector> #include <cmath> #include <pthread.h> #include <unistd.

#include <stdlib.h> #include <stdio.h> #include opencv2/opencv.hpp #include <vector> #include <cmath> #include <pthread.h> #include <unistd. #include #include #include "opencv2/opencv.hpp" #include #include #include #include #include "LineDesc.h" #include "PotentialBug.h" #include

More information

Homework 4: (GRADUATE VERSION)

Homework 4: (GRADUATE VERSION) Homework 4: Wavefront Path Planning and Path Smoothing (GRADUATE VERSION) Assigned: Thursday, October 16, 2008 Due: Friday, October 31, 2008 at 23:59:59 In this assignment, you will write a path planner

More information

First C or C++ Lab Paycheck-V1.0 Using Microsoft Visual Studio

First C or C++ Lab Paycheck-V1.0 Using Microsoft Visual Studio C & C++ LAB ASSIGNMENT #1 First C or C++ Lab Paycheck-V1.0 Using Microsoft Visual Studio Copyright 2013 Dan McElroy Paycheck-V1.0 The purpose of this lab assignment is to enter a C or C++ into Visual Studio

More information

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures

Agenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references Memory regions 2 EACH C++ VARIABLE IS STORED IN A

More information

Lab#5 Due Wednesday, February 25, at the start of class. Purpose: To develop familiarity with C++ pointer variables

Lab#5 Due Wednesday, February 25, at the start of class. Purpose: To develop familiarity with C++ pointer variables Lab#5 Due Wednesday, February 25, at the start of class Purpose: To develop familiarity with C++ pointer variables Introduction: In this lab, you will learn by experimentation the answers to some questions

More information

... Print PROGRAMS\Final Project final\planes\planeshoot.c 1

... Print PROGRAMS\Final Project final\planes\planeshoot.c 1 ... Print PROGRAMS\Final Project final\planes\planeshoot.c 1 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include

More information

As an example using arrays, let s write some code to get started with the Upthrust game. We can use a 2D array to represent the game board.

As an example using arrays, let s write some code to get started with the Upthrust game. We can use a 2D array to represent the game board. Array Example Upthrust Board As an example using arrays, let s write some code to get started with the Upthrust game. We can use a 2D array to represent the game board. First, note that the game board

More information

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points)

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points) Name rue or False (12 Points) 1. (12 pts) Circle for true and F for false: F a) Local identifiers have name precedence over global identifiers of the same name. F b) Local variables retain their value

More information

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

COMP322 - Introduction to C++ Lecture 02 - Basics of C++ COMP322 - Introduction to C++ Lecture 02 - Basics of C++ School of Computer Science 16 January 2012 C++ basics - Arithmetic operators Where possible, C++ will automatically convert among the basic types.

More information

The University of Nottingham

The University of Nottingham The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, AUTUMN SEMESTER 2008 2009 C/C++ for Java Programmers Time allowed TWO hours Candidates may complete the front cover of their answer

More information

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function CMPT 127 Spring 2019 Grade: / 20 First name: Last name: Student Number: Lab Exam 1 D400 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return -1? Answer:

More information

CSCE 110 PROGRAMMING FUNDAMENTALS

CSCE 110 PROGRAMMING FUNDAMENTALS CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class Prof. amr Goneid, AUC 1 Dictionaries(1): A Key Table Class Prof. Amr Goneid, AUC 2 A Key Table

More information

Communication With the Outside World

Communication With the Outside World Communication With the Outside World Program Return Code Arguments From the Program Call Aborting Program Calling Other Programs Data Processing Course, I. Hrivnacova, IPN Orsay I. Hrivnacova @ Data Processing

More information

ECE 462 Fall 2011, Third Exam

ECE 462 Fall 2011, Third Exam ECE 462 Fall 2011, Third Exam DO NOT START WORKING ON THIS UNTIL TOLD TO DO SO. You have until 9:20 to take this exam. Your exam should have 12 pages total (including this cover sheet). Please let Prof.

More information

BEng (Hons) Electronic Engineering. Resit Examinations for / Semester 1

BEng (Hons) Electronic Engineering. Resit Examinations for / Semester 1 BEng (Hons) Electronic Engineering Cohort: BEE/10B/FT Resit Examinations for 2016-2017 / Semester 1 MODULE: Programming for Engineers MODULE CODE: PROG1114 Duration: 3 Hours Instructions to Candidates:

More information

Object Oriented Design

Object Oriented Design Object Oriented Design Lecture 3: Introduction to C++ (Continue) Examples using declarations that eliminate the need to repeat the std:: prefix 1 Examples using namespace std; enables a program to use

More information

Philip Calderon CSE 520 Lab 3 Color Shader

Philip Calderon CSE 520 Lab 3 Color Shader Philip Calderon CSE 520 Lab 3 Color Shader Summary: The purpose of lab 4 is to produce a pyramid tetrahedron that we are able to rotate it when clicked. Part 1: Color Tetrahedron Part 2: Rotation to show

More information

THE INTEGER DATA TYPES. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

THE INTEGER DATA TYPES. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski) THE INTEGER DATA TYPES STORAGE OF INTEGER TYPES IN MEMORY All data types are stored in binary in memory. The type that you give a value indicates to the machine what encoding to use to store the data in

More information

Unit 6 Files. putchar(ch); ch = getc (fp); //Reads single character from file and advances position to next character

Unit 6 Files. putchar(ch); ch = getc (fp); //Reads single character from file and advances position to next character 1. What is File management? In real life, we want to store data permanently so that later on we can retrieve it and reuse it. A file is a collection of bytes stored on a secondary storage device like hard

More information

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy CSCI 334: Principles of Programming Languages Lecture 18: C/C++ Homework help session will be tomorrow from 7-9pm in Schow 030A instead of on Thursday. Instructor: Dan Barowy HW6 and HW7 solutions We only

More information

File I/O. Arash Rafiey. November 7, 2017

File I/O. Arash Rafiey. November 7, 2017 November 7, 2017 Files File is a place on disk where a group of related data is stored. Files File is a place on disk where a group of related data is stored. C provides various functions to handle files

More information

Chapter 10 RECORDS (Structs )

Chapter 10 RECORDS (Structs ) Chapter 10 RECORDS (Structs ) In Chapter 6 we learned that an array is set up to use multiple elements of the same data type. What if we want to have several different related types within one data structure

More information

Fortran Standards Toolkit (FST)

Fortran Standards Toolkit (FST) NCAR/SIParCS/CISL Fortran Standards Toolkit (FST) Frank Duffy SIParCS Dan Nagle, Davide Del Vento Bridgewater State University Bridgewater MA August 1, 2018 What is FST? An ongoing project Mission: provide

More information

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable Basic C++ Overview C++ is a version of the older C programming language. This is a language that is used for a wide variety of applications and which has a mature base of compilers and libraries. C++ is

More information

CHAPTER 3 BASIC INSTRUCTION OF C++

CHAPTER 3 BASIC INSTRUCTION OF C++ CHAPTER 3 BASIC INSTRUCTION OF C++ MOHD HATTA BIN HJ MOHAMED ALI Computer programming (BFC 20802) Subtopics 2 Parts of a C++ Program Classes and Objects The #include Directive Variables and Literals Identifiers

More information

MPI 3. CSCI 4850/5850 High-Performance Computing Spring 2018

MPI 3. CSCI 4850/5850 High-Performance Computing Spring 2018 MPI 3 CSCI 4850/5850 High-Performance Computing Spring 2018 Tae-Hyuk (Ted) Ahn Department of Computer Science Program of Bioinformatics and Computational Biology Saint Louis University Learning Objectives

More information

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol. 1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol. B. Outputs to the console a floating point number f1 in scientific format

More information

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming

More information

Exceptions, Case Study-Exception handling in C++.

Exceptions, Case Study-Exception handling in C++. PART III: Structuring of Computations- Structuring the computation, Expressions and statements, Conditional execution and iteration, Routines, Style issues: side effects and aliasing, Exceptions, Case

More information

More on Func*ons Command Line Arguments CS 16: Solving Problems with Computers I Lecture #8

More on Func*ons Command Line Arguments CS 16: Solving Problems with Computers I Lecture #8 More on Func*ons Command Line Arguments CS 16: Solving Problems with Computers I Lecture #8 Ziad Matni Dept. of Computer Science, UCSB Announcements Homework #7 due today Lab #4 is due on Monday at 8:00

More information

CMSC 202 Midterm Exam 1 Fall 2015

CMSC 202 Midterm Exam 1 Fall 2015 1. (15 points) There are six logic or syntax errors in the following program; find five of them. Circle each of the five errors you find and write the line number and correction in the space provided below.

More information

CSCE Practice Midterm. Data Types

CSCE Practice Midterm. Data Types CSCE 2004 - Practice Midterm This midterm exam was given in class several years ago. Work each of the following questions on your own. Once you are done, check your answers. For any questions whose answers

More information

1. Word Analysis: (Which nouns suggest a need for memory (a variable) and which verbs suggest a need for action (a function maybe).

1. Word Analysis: (Which nouns suggest a need for memory (a variable) and which verbs suggest a need for action (a function maybe). Program 3 Seven Step Problem Solving Methodology Skeleton Problem Statement for Body Mass Index Program Enhancement: Design a program that calculates a person s body mass index (BMI). The BMI is often

More information

C++ For Science and Engineering Lecture 12

C++ For Science and Engineering Lecture 12 C++ For Science and Engineering Lecture 12 John Chrispell Tulane University Monday September 20, 2010 Comparing C-Style strings Note the following listing dosn t do what you probably think it does (assuming

More information

CSC 270 Survey of Programming Languages. Input and Output

CSC 270 Survey of Programming Languages. Input and Output CSC 270 Survey of Programming Languages C Lecture 8 Input and Output Input and Output C supports 2 different I/O libraries: buffered (higher level functions supported by ANSI standards) unbuffered (lower-level

More information

STL. Prof Tejada Week 14

STL. Prof Tejada Week 14 STL Prof Tejada Week 14 Standard Template Library (STL) What is the STL? A generic collection of commonly used data structures and algorithms In 1994, STL was adopted as a standard part of C++ Why used

More information

CE221 Programming in C++ Part 1 Introduction

CE221 Programming in C++ Part 1 Introduction CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab

More information

Chapter 1 - What s in a program?

Chapter 1 - What s in a program? Chapter 1 - What s in a program? I. Student Learning Outcomes (SLOs) a. You should be able to use Input-Process-Output charts to define basic processes in a programming module. b. You should be able to

More information

Lecture 5 Files and Streams

Lecture 5 Files and Streams Lecture 5 Files and Streams Introduction C programs can store results & information permanently on disk using file handling functions These functions let you write either text or binary data to a file,

More information

CS 376b Computer Vision

CS 376b Computer Vision CS 376b Computer Vision 09 / 25 / 2014 Instructor: Michael Eckmann Today s Topics Questions? / Comments? Enhancing images / masks Cross correlation Convolution C++ Cross-correlation Cross-correlation involves

More information