! " # $ %& %' ( ) ) *%%+, -..*/ *%%+ - 0 ) 1 2 1



Similar documents
CpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing

Basics of I/O Streams and File I/O

Comp151. Definitions & Declarations

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Appendix K Introduction to Microsoft Visual C++ 6.0

Member Functions of the istream Class

C++ Input/Output: Streams

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Binary storage of graphs and related data

Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example

C++ INTERVIEW QUESTIONS

For the next three questions, consider the class declaration: Member function implementations put inline to save space.

Ch 7-1. Object-Oriented Programming and Classes

Compiler Construction

CSI33 Data Structures

Appendix M: Introduction to Microsoft Visual C Express Edition

C++ Outline. cout << "Enter two integers: "; int x, y; cin >> x >> y; cout << "The sum is: " << x + y << \n ;

Arrays. number: Motivation. Prof. Stewart Weiss. Software Design Lecture Notes Arrays

7.7 Case Study: Calculating Depreciation

IS0020 Program Design and Software Tools Midterm, Feb 24, Instruction

CISC 181 Project 3 Designing Classes for Bank Accounts

N3458: Simple Database Integration in C++11

Using C++ File Streams

EP241 Computer Programming

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

C++FA 5.1 PRACTICE MID-TERM EXAM

Reading and Writing PCD Files The PCD File Format The Grabber Interface Writing a Custom Grabber PCL :: I/O. Suat Gedikli, Nico Blodow

Object Oriented Software Design II

Basics of C++ and object orientation in OpenFOAM

El Dorado Union High School District Educational Services

Bevezetés a C++ Standard Template Library-be

Passing 1D arrays to functions.

CSCI 123 INTRODUCTION TO PROGRAMMING CONCEPTS IN C++

An Incomplete C++ Primer. University of Wyoming MA 5310

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

CORBA Programming with TAOX11. The C++11 CORBA Implementation

MS Visual C++ Introduction. Quick Introduction. A1 Visual C++

The Payroll Program. Payroll

13 Classes & Objects with Constructors/Destructors

Function Overloading I

Answers to Review Questions Chapter 7

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

Illustration 1: Diagram of program function and data flow

AP Computer Science Java Subset

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Subject Name: Object Oriented Programming in C++ Subject Code:

Cours de C++ Utilisations des conteneurs

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)

Block I Apollo Guidance Computer (AGC)

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 3: Input/Output

C++ Programming Language

! 2!!$ ,)!$- %$0. Baskı-2 ! "! #$ % #$#!&'! '! (&&)!! &!! #.! &)!$#$! /&)!!! 0! &)!$!.!! 0$! #! &)!$ &.!!#$!! 3!&!#!!3! #&!'! &! 4!!

The little endl that couldn t

C++ Crash Kurs. C++ Object-Oriented Programming

Copyright 2001, Bill Trudell. Permission is granted to copy for the PLoP 2001 conference. All other rights reserved.

Integrating the C++ Standard Template Library Into the Undergraduate Computer Science Curriculum

The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures

How to: Use Basic C++, Syntax and Operators

sqlpp11 - An SQL Library Worthy of Modern C++

More C++ Concepts. Operator overloading Friend Function This Operator Inline Function

Moving from C++ to VBA

CS193D Handout 06 Winter 2004 January 26, 2004 Copy Constructor and operator=

COMPUTER SCIENCE 1999 (Delhi Board)

Note: Syntactically, a ; is needed at the end of a struct definition.

C++ Language Tutorial

Konzepte objektorientierter Programmierung

Conditions & Boolean Expressions

5 CLASSES CHAPTER. 5.1 Object-Oriented and Procedural Programming. 5.2 Classes and Objects 5.3 Sample Application: A Clock Class

Short Notes on Dynamic Memory Allocation, Pointer and Data Structure

Chapter 5 Functions. Introducing Functions

Data Structures using OOP C++ Lecture 1

While Loop. 6. Iteration

Telit AppZone Programming Tips

Syllabus OBJECT ORIENTED PROGRAMMING C++

The University of Alabama in Huntsville Electrical and Computer Engineering CPE Test #4 November 20, True or False (2 points each)

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++)

KLV encoder / decoder library for STANAG 4609

6. Control Structures

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

Polymorphism. Problems with switch statement. Solution - use virtual functions (polymorphism) Polymorphism

Visual Studio 2008 Express Editions

/* File: blkcopy.c. size_t n

Calling the Function. Two Function Declarations Here is a function declared as pass by value. Why use Pass By Reference?

C++ Support for Abstract Data Types

Queue Implementations

The separation principle : a principle for programming language design

Chapter 5. Selection 5-1


Course notes Standard C++ programming

C++FA 3.1 OPTIMIZING C++

Chapter 9 Text Files User Defined Data Types User Defined Header Files

Software Engineering Concepts: Testing. Pointers & Dynamic Allocation. CS 311 Data Structures and Algorithms Lecture Slides Monday, September 14, 2009

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Object Oriented Software Design II

The if Statement and Practice Problems

Transcription:

!" #$%&%'())*%%+,-..*/*%%+- 0 )12 1

*!" 34 5 6 * #& ) 7 8 5)# 97&)8 5)# 9 : & ; < 5 11 8 1 5)=19 7 19 : 0 5)=1 ) & & >) ) >) 1? 5)= 19 7 19 : # )! #"&@)1 # )? 1 1#& 5)=19719:# 1 5)=9 7 9 : 11 0 #) 5 A 0 A & ) 5 # ) < 1 1 B,!:, "8 >)! >) " ) @)1# ) 5)= 11 #include <iostream> #include <fstream> #include "vblib.h" // VBString using namespace std; // prototypes of standard library // char toupper(char c); // char tolower(char c); // exteded chars to change (global variables) char chghicaps[] = "ÁÉÍÓÚÃÕÑÀÈÌÒÙÜÇÂÊÎÔÛ"; char chglocaps[] = "áéíóúãõñàèìòùüçâêîôû"; char extendedtoupper(char in) // add code here char extendedtolower(char in) // add code here void converttoupper(char* buf) int len = strlen(buf); for (int i=0 ; i < len ; i++) // buf[i] = toupper(buf[i]); // commented out buf[i] = extendedtoupper(buf[i]); void converttolower(char* buf) int len = strlen(buf); for (int i=0 ; i < len ; i++) // buf[i] = tolower(buf[i]); // commented out

+ buf[i] = extendedtolower(buf[i]); VBString s; ifstream originalfile("original.txt"); ofstream toupperfile("toupper.txt"); ofstream tolowerfile("tolower.txt"); if (!originalfile!toupperfile! tolowerfile) cout << "File not open" << endl; exit(1); char *buffer; while (true) originalfile >> s; if (originalfile.eof()) break; buffer = new char [strlen(s) + 1]; // +1 for the terminator char strcpy(buffer,s); converttoupper(buffer); toupperfile << buffer << endl; converttolower(buffer); tolowerfile << buffer << endl; delete [] buffer; cout << "done" << endl; return 0; #" ) @) ) @)1C D & 5 E E* E ( 1 @)1& ;& C) F G D& @) F G 8 @)1 C D(> ) @)1C)F G D8) F G $" ) @) ) @)1! " Título da tabela Nome do cliente,telefone do cliente, código do cliente Caetano Veloso,222-3344,29837 Jô Soares,234-5678,31232...

H Gilberto Gil,256-9876,28763 ) I <font color="#001122"> <h1>título da tabela</h1> <table border="1"> <tr> <td>nome do cliente</td> <td>telefone do cliente</td> <td>código do cliente</td> </tr><tr> <td>caetano Veloso</td><td>2222-3344</td><td>29837</td> </tr><tr> <td>jô Soares</td><td>2234-5678</td><td>31232</td> </tr> <!--... --> <tr> <td>gilberto Gil</td><td>2256-9876</td><td>28763</td> </tr> </table> </font>! ) 5J & I &1 8 " 9I) 9 K 9 5,;, ****++HH *.$+L MN **+HO'L$ +*+* P P **O'.$L' *$L'+ %" ( ) @) # <5 85 6 )) ) 18 ) #! (3," @)4 5 #&8@) ) & 8 @) ) ) # & ( 8-3 15 5 &4!" # #) #7 #8 #!3 K "& ) 8 5 ) #&! " "K & ; & ) ) = -3 *",5 & 5 # #! C, QD "! @) ) #"< 5 @) 4 # )

O #include "vblib.h" // add code here for exception handling of nodatabasename and badpassword class MyDataBase VBString m_data; bool m_connected; MyDataBase() // default constructor m_connected = false; void connect(vbstring name, VBString login, VBString password) // connect to database bool nameok = (name == "databasename"); if (!nameok) throw MyDataBaseException_NoDataBaseName(); ; bool passwordok = ((login == "databaselogin") && (password == "databasepassword")) ; if (!passwordok) throw MyDataBaseException_BadPassword(); m_connected = true; MyDataBase obj; VBString name = "databasename"; VBString login = "databaselogin"; VBString password = "databasepassword"; try obj.connect(name,login,password); catch (const MyDataBaseException_BadPassword & E) E.ShowExplanation(); catch (const MyDataBaseException_NoDataBaseName & E) E.ShowExplanation(); cout << "Connection to database ok" << endl; &" 4 ) @)1 & )4 5 8 C RR ) R K D& &5 name1;80.1;1.77;1933 name2;66.6;1.85;1930 name3;88.4;1.71;1944

' ( J @)1 & ) 0 ) & ) - >! "( # 5 & 5)# )E& ) 1 ", & ; *"? @) 5 6 #include <iostream> #include <fstream> #include "vblib.h" using namespace std; template <class T> void bubble_sort(t* array, int n, bool (*compare)(t,t)) for (int i=0 ; i < n ; i++) for (int j=i+1 ; j < n ; j++) if (compare(array[i],array[j])) // swap (array[i], array[j]) T temp = array[i]; array[i] = array[j]; array[j] = temp; struct Person VBString m_name; float m_weight; float m_height; int m_yearofbitrh; friend ostream & operator<<(ostream & stream, Person &obj); ; // if necessary, add code here (aux) // overload insersor ostream & operator << (ostream & stream, Person & obj) // add code here (1) Person decodestringforperson(vbstring s) // add code here (2) const char *filename = "t.txt"; ifstream myfile(filename); if (!myfile) cout << "File not open" << endl; exit(1); VBList<Person> personlist;

L VBString s; Person p; Person *pp; int n=0; while (true) myfile >> s; if (myfile.eof()) break; p = decodestringforperson(s); personlist.add(p); n++; // create an array of person of the same dimension of data in the linked list Person *personarray = new person [n]; // copy data from linked list to array, to let data be sorted using bubble sort int i=0; // add code here (4) cout << "Unsorted data" << endl; for (i=0 ; i < n ; i++) cout << personarray[i] << endl; bubble_sort(personarray,n,comparepersonperage); cout << "Sorted data, by age" << endl; for (i=0 ; i < n ; i++) cout << personarray[i] << endl; delete [] personarray; // not to leak memory '" 4 @)1 5 C D& 9 ) @)1& @) 8) > &@)8 @) )@), @)1 )! & 3K &") &@)4 8 411& 1 5 Giberto Gil,1954,1.72 Chico Buarque,1951,1.74 João Gilberto,1960,1.68 Tom Jobim,1959,1.79 Caetano Veloso,1955,1.71 ( )) < -&@))) 0 1 ) - # 6 @)1 ; 8!J @)1 6 - " ; 8!> -"

$ #include <fstream> #include "vblib.h" struct Person VBString m_name; unsigned m_yearofbirth; float m_weight; char m_tok; Person() m_tok = ','; // overload insersor friend ostream & operator <<(ostream & stream, Person &obj) stream << obj.m_name << obj.m_tok << obj.m_yearofbirth << obj.m_tok << obj.m_weight; return stream; // overload extrator friend istream & operator>>(istream & stream, Person &obj) VBString aux; stream >> aux; // read all attributes of object in one string obj.m_name = aux.strtok(obj.m_tok,0); obj.m_yearofbirth = atoi(aux.strtok(obj.m_tok,1)); obj.m_weight = atof(aux.strtok(obj.m_tok,3)); return stream; ; class PersonArray Person *m_p_person; unsigned m_size; void mydelete() if (m_p_person) delete[] m_p_person; m_p_person = 0; void allocarray(unsigned size) m_size = size; m_p_person = new Person[size]; PersonArray() m_p_person = 0; ~PersonArray() mydelete(); void readfromfile(const char *filename) // add code here

. void show() // add code here ; const char *filename = "data.txt"; PersonArray a; a.readfromfile(filename); a.show(); return 0; < I 1 ========================= Array of Person Giberto Gil,1954,1.72 Chico Buarque,1951,1.74 João Gilberto,1960,1.68 Tom Jobim,1959,1.79 Caetano Veloso,1955,1.71 0@) 1!# 1 ;" 1J 5 1) ; ) 8 (!( "& < -& 5 @) # (" < ) & ),)! "& @) 8 * ) 0 ) #,, )& ; 7 4, )15) # ) 4 ) 5 5& <, ) 8 1 F F #include <iostream> #define VBLIB_USE_NAMESPACE_STD #include "vblib.h" using namespace std; class Couple VBString m_namehim, m_nameher; void sethim(vbstring him) m_namehim = him; void sether(vbstring her) m_nameher = her; // add code here ; Couple c1,c2; VBString extra = " NOME EXTRA ";

% c1.sethim("nome dele"); c1.sether("nome dela"); c2 = c1 + extra; cout << c2 << endl; c2 = extra + c1; cout << c2 << endl; return 0; I Nome dele NOME EXTRA :Nome dela NOME EXTRA NOME EXTRA Nome dele: NOME EXTRA Nome dela " )" ( 8@)) CS T U D&@) 5 @)# ), 1&+@) STU( #& ) 5 K 1 #&) #K #5& 8 ) # (; &#5 ) # ) ) # ) #)) # ) 5, 5 & 5 ) # @) 5 6 #include <iostream> using namespace std; class XYZ_ExceptionHandler ; class XYZ_Connect bool actualconnectcode() // real code will be inserted here later // return code true means an error happened return false; void connect() bool failconnect = actualconnectcode(); if (failconnect) XYZ_ExceptionHandler e; throw e;

; class XYZ_CheckPassword bool actualcode() // real code will be inserted here later // return code true means an error happened return false; void CheckPassword() bool fail = actualcode(); if (fail) XYZ_ExceptionHandler e; throw e; ; try XYZ_Connect con; con.connect(); cout << "connected!" << endl; XYZ_CheckPassword passwd; passwd.checkpassword(); cout << "password ok!" << endl; catch (XYZ_ExceptionHandler e) cout << "XYZ exception." << endl; catch (...) cout << "Unknown exception" << endl; return 0;