Enviar pesquisa
Carregar
C++ programming intro
•
4 gostaram
•
1,506 visualizações
M
marklaloo
Seguir
Denunciar
Compartilhar
Denunciar
Compartilhar
1 de 22
Baixar agora
Baixar para ler offline
Recomendados
C programming Ms. Pranoti Doke
C programming Ms. Pranoti Doke
Pranoti Doke
C++ Programming
C++ Programming
Rounak Samdadia
C programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti Doke
Pranoti Doke
C++ Basics
C++ Basics
Himanshu Sharma
Programming of c++
Programming of c++
Ateeq Sindhu
C101 – Intro to Programming with C
C101 – Intro to Programming with C
gpsoft_sk
Complete C++ programming Language Course
Complete C++ programming Language Course
Vivek chan
C++
C++
Neha Gupta
Recomendados
C programming Ms. Pranoti Doke
C programming Ms. Pranoti Doke
Pranoti Doke
C++ Programming
C++ Programming
Rounak Samdadia
C programming_MSBTE_Diploma_Pranoti Doke
C programming_MSBTE_Diploma_Pranoti Doke
Pranoti Doke
C++ Basics
C++ Basics
Himanshu Sharma
Programming of c++
Programming of c++
Ateeq Sindhu
C101 – Intro to Programming with C
C101 – Intro to Programming with C
gpsoft_sk
Complete C++ programming Language Course
Complete C++ programming Language Course
Vivek chan
C++
C++
Neha Gupta
Keywords, identifiers ,datatypes in C++
Keywords, identifiers ,datatypes in C++
Ankur Pandey
C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1
Ali Raza Jilani
C++ Programming Course
C++ Programming Course
Dennis Chang
Intro to C++ - language
Intro to C++ - language
Jussi Pohjolainen
C language
C language
SMS2007
The smartpath information systems c plus plus
The smartpath information systems c plus plus
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
C programming & data structure [character strings & string functions]
C programming & data structure [character strings & string functions]
MomenMostafa
C language (Collected By Dushmanta)
C language (Collected By Dushmanta)
Dushmanta Nath
Basics of c++
Basics of c++
Huba Akhtar
Learning C++ - Introduction to c++ programming 1
Learning C++ - Introduction to c++ programming 1
Ali Aminian
C programming notes
C programming notes
Prof. Dr. K. Adisesha
C programming session 01
C programming session 01
Dushmanta Nath
C++ for beginners
C++ for beginners
Salahaddin University-Erbil
Introduction to c language
Introduction to c language
RavindraSalunke3
C++ How to program
C++ How to program
Mohammad Golyani
C++
C++
k v
Structures-2
Structures-2
arshpreetkaur07
Basic C Programming language
Basic C Programming language
Abhishek Soni
Unit 4 Foc
Unit 4 Foc
JAYA
basics of C and c++ by eteaching
basics of C and c++ by eteaching
eteaching
2 Intro c++
2 Intro c++
Docent Education
A quick and dirty intro to objective c
A quick and dirty intro to objective c
Billy Abbott
Mais conteúdo relacionado
Mais procurados
Keywords, identifiers ,datatypes in C++
Keywords, identifiers ,datatypes in C++
Ankur Pandey
C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1
Ali Raza Jilani
C++ Programming Course
C++ Programming Course
Dennis Chang
Intro to C++ - language
Intro to C++ - language
Jussi Pohjolainen
C language
C language
SMS2007
The smartpath information systems c plus plus
The smartpath information systems c plus plus
The Smartpath Information Systems,Bhilai,Durg,Chhattisgarh.
C programming & data structure [character strings & string functions]
C programming & data structure [character strings & string functions]
MomenMostafa
C language (Collected By Dushmanta)
C language (Collected By Dushmanta)
Dushmanta Nath
Basics of c++
Basics of c++
Huba Akhtar
Learning C++ - Introduction to c++ programming 1
Learning C++ - Introduction to c++ programming 1
Ali Aminian
C programming notes
C programming notes
Prof. Dr. K. Adisesha
C programming session 01
C programming session 01
Dushmanta Nath
C++ for beginners
C++ for beginners
Salahaddin University-Erbil
Introduction to c language
Introduction to c language
RavindraSalunke3
C++ How to program
C++ How to program
Mohammad Golyani
C++
C++
k v
Structures-2
Structures-2
arshpreetkaur07
Basic C Programming language
Basic C Programming language
Abhishek Soni
Unit 4 Foc
Unit 4 Foc
JAYA
basics of C and c++ by eteaching
basics of C and c++ by eteaching
eteaching
Mais procurados
(20)
Keywords, identifiers ,datatypes in C++
Keywords, identifiers ,datatypes in C++
C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1
C++ Programming Course
C++ Programming Course
Intro to C++ - language
Intro to C++ - language
C language
C language
The smartpath information systems c plus plus
The smartpath information systems c plus plus
C programming & data structure [character strings & string functions]
C programming & data structure [character strings & string functions]
C language (Collected By Dushmanta)
C language (Collected By Dushmanta)
Basics of c++
Basics of c++
Learning C++ - Introduction to c++ programming 1
Learning C++ - Introduction to c++ programming 1
C programming notes
C programming notes
C programming session 01
C programming session 01
C++ for beginners
C++ for beginners
Introduction to c language
Introduction to c language
C++ How to program
C++ How to program
C++
C++
Structures-2
Structures-2
Basic C Programming language
Basic C Programming language
Unit 4 Foc
Unit 4 Foc
basics of C and c++ by eteaching
basics of C and c++ by eteaching
Destaque
2 Intro c++
2 Intro c++
Docent Education
A quick and dirty intro to objective c
A quick and dirty intro to objective c
Billy Abbott
Turbo c++
Turbo c++
vaibhav1996
Apclass
Apclass
geishaannealagos
Overview of c++ language
Overview of c++ language
samt7
Templates presentation
Templates presentation
malaybpramanik
Introduction to visual basic programming
Introduction to visual basic programming
Roger Argarin
Destaque
(7)
2 Intro c++
2 Intro c++
A quick and dirty intro to objective c
A quick and dirty intro to objective c
Turbo c++
Turbo c++
Apclass
Apclass
Overview of c++ language
Overview of c++ language
Templates presentation
Templates presentation
Introduction to visual basic programming
Introduction to visual basic programming
Semelhante a C++ programming intro
Abhishek lingineni
Abhishek lingineni
abhishekl404
CPlusPus
CPlusPus
rasen58
C++_programs.ppt
C++_programs.ppt
Dikshithkumar10
C++_programs.ppt
C++_programs.ppt
Infotech27
C++_programs.ppt
C++_programs.ppt
TeacherOnat
C++_programs.ppt
C++_programs.ppt
JayarAlejo
C++_programs.ppt
C++_programs.ppt
JayarAlejo
C++_programs.ppt
C++_programs.ppt
EPORI
C++ programming: Basic introduction to C++.ppt
C++ programming: Basic introduction to C++.ppt
yp02
Cs1123 11 pointers
Cs1123 11 pointers
TAlha MAlik
Learn c++ Programming Language
Learn c++ Programming Language
Steve Johnson
Cs1123 3 c++ overview
Cs1123 3 c++ overview
TAlha MAlik
c++ UNIT II.pptx
c++ UNIT II.pptx
Kongunadu College of Engineering and Technology
Introduction to C++
Introduction to C++
Sikder Tahsin Al-Amin
C cpluplus 2
C cpluplus 2
sanya6900
Introduction to C#
Introduction to C#
ANURAG SINGH
c programming L-1.pdf43333333544444444444444444444
c programming L-1.pdf43333333544444444444444444444
PurvaShyama
lecture02-cpp.ppt
lecture02-cpp.ppt
ssuser0c24d5
lecture02-cpp.ppt
lecture02-cpp.ppt
nilesh405711
lecture02-cpp.ppt
lecture02-cpp.ppt
YashpalYadav46
Semelhante a C++ programming intro
(20)
Abhishek lingineni
Abhishek lingineni
CPlusPus
CPlusPus
C++_programs.ppt
C++_programs.ppt
C++_programs.ppt
C++_programs.ppt
C++_programs.ppt
C++_programs.ppt
C++_programs.ppt
C++_programs.ppt
C++_programs.ppt
C++_programs.ppt
C++_programs.ppt
C++_programs.ppt
C++ programming: Basic introduction to C++.ppt
C++ programming: Basic introduction to C++.ppt
Cs1123 11 pointers
Cs1123 11 pointers
Learn c++ Programming Language
Learn c++ Programming Language
Cs1123 3 c++ overview
Cs1123 3 c++ overview
c++ UNIT II.pptx
c++ UNIT II.pptx
Introduction to C++
Introduction to C++
C cpluplus 2
C cpluplus 2
Introduction to C#
Introduction to C#
c programming L-1.pdf43333333544444444444444444444
c programming L-1.pdf43333333544444444444444444444
lecture02-cpp.ppt
lecture02-cpp.ppt
lecture02-cpp.ppt
lecture02-cpp.ppt
lecture02-cpp.ppt
lecture02-cpp.ppt
C++ programming intro
1.
CS 342: Intro
to C++ Programming A Simple C++ Program #include <iostream> using namespace std; int main() { cout << “hello, world!” << endl; return 0; } Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
2.
CS 342: Intro
to C++ Programming #include <iostream> • #include tells the precompiler to include a file • Usually, we include header files – Contain declarations of structs, classes, functions • Sometimes we include template definitions – Varies from compiler to compiler – Advanced topic we’ll cover later in the semester • <iostream> is the C++ label for a standard header file for input and output streams Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
3.
CS 342: Intro
to C++ Programming using namespace std; • The using directive tells the compiler to include code from libraries in a separate namespace – Similar idea to Ada/Pascal “packages” • C++ provides such a namespace for its standard library – cout, cin, cerr standard iostreams and much more • Namespaces reduce collisions between symbols – If another library defined cout we could say std::cout • Can also apply using more selectively: – E.g., just using std::cout Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
4.
CS 342: Intro
to C++ Programming int main() • Declares the main function of any C++ program • Here, takes no parameters and returns an integer – By convention in UNIX and many other platforms • returning 0 means success • returning non-zero indicates failure (may return error codes) • Who calls main? – The runtime environment (often from a function called crt0) • What about the stuff in braces? – It’s the body of function main, its definition Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
5.
CS 342: Intro
to C++ Programming cout<<“hello, world!”<<endl; • Uses the standard output iostream, named cout – For standard input, use cin – For standard error, use cerr • << is an operator for inserting into the stream – A member “function” of the ostream class – Returns a reference to stream on which its called – Can be applied repeatedly to references left-to-right • “hello, world!” is a C-style string – A 14-postion character array terminated by ‘0’ • endl is an iostream manipulator – Ends the line, by inserting end-of-line character(s) – Also flushes the stream Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
6.
CS 342: Intro
to C++ Programming A Slightly Bigger C++ Program #include <iostream> using namespace std; int main(int argc, char * argv[]) { for (int i = 0; i < argc; ++i) { cout << argv[i] << endl; } return 0; } Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
7.
CS 342: Intro
to C++ Programming int argc, char * argv[] • A way to affect the program’s behavior – Carry parameters with which program was called – Passed as parameters to main from crt0 – Passed by value (we’ll discuss what that means) • argc – An integer with the number of parameters (>=1) • argv – An array of pointers to C-style character strings – Its array-length is the value stored in argc – The name of the program is kept in argv[0] Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
8.
CS 342: Intro
to C++ Programming for(int i = 0; i < argc; ++i) • Standard C++ for loop syntax – Initialization statement done once at start of loop – Test expression done before running each time – Expression to increment after running each time • int i = 0 – Declares integer i (scope is the loop itself) – Initializes i to hold value 0 • i < argc – Tests whether or not we’re still inside the array! – Reading/writing memory we don’t own can crash the program (if we’re really lucky!) • ++i – increments the array position Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
9.
CS 342: Intro
to C++ Programming {cout << argv[i] << endl;} • Body of the for loop • You should use braces, even if there’s only one line of code – Avoids maintenance errors when adding/modifying code – Ensures semantics & indentation say same thing • argv[i] – An example of array indexing – Specifies ith position from start of argv Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
10.
CS 342: Intro
to C++ Programming C++ Types • int, long, short, char (integer division) • float, double (floating point division) • signed (default) and unsigned types • bool type • enumerations – enum primary_colors {red, blue, yellow}; • structs and classes • pointers and references • mutable (default) vs. const types Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
11.
CS 342: Intro
to C++ Programming C++ Loops and Conditionals • Loops – for – while – do • Conditionals – if, else, else if – ?: operator – switch Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
12.
CS 342: Intro
to C++ Programming C++ Operators • Relational operators == <= >= < > != • Assignment operators = *= /= %= += -= &= |= • Logical operators ! && || • Member selection operators -> . All of these return values – Be careful of == and = Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
13.
CS 342: Intro
to C++ Programming C++ Functions • In C++, behavior need not be part of a class – We’ll distinguish “plain old” functions vs. member functions • Pass parameters by reference vs. by value • Put declaration prototypes (no body) in header files • Put definitions in source files (compilation units) • Libraries often offer lots of helpful functions – E.g., isalpha () from the <cctype> library Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
14.
CS 342: Intro
to C++ Programming Parameter/Variable Declarations • Read a function parameter or local variable declaration right to left int i; “i is an integer” int & r; “r is a reference to an integer” int * p; “p is a pointer to an integer” int * & q; “q is a reference to a pointer to an integer” int * const c; “c is a const pointer to an integer” int const * d; “d is a pointer to a const integer” • Read a function pointer declaration inside out – More on this later Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
15.
CS 342: Intro
to C++ Programming Pass By Reference void foo() { int i = 7; local variable i baz (i); 7 ? 3 } void baz(int & j) { j = 3; 7 ? 3 } j is a reference to the variable passed to baz Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
16.
CS 342: Intro
to C++ Programming Pass By Value void foo() { int i = 7; 7 local variable i baz (i); } void baz(int j) { j = 3; local variable j 7 ? 3 (initialized with the value } passed to baz) Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
17.
CS 342: Intro
to C++ Programming C++ Classes and Structs • Struct members are public struct MyData { by default MyData(int i) :m_x(i){} • Class members are int m_x; private by default }; • Both can have – Constructors – Destructors class MyObject { – Member variables public: – Member functions MyObject(int y); ~MyObject(); • Common practice: private: – use structs for data int m_y; – use classes for objects with methods }; • Declarations usually go in header files Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
18.
CS 342: Intro
to C++ Programming C++ Classes and Structs We also need an implementation – Generally in the .cpp file MyObject::MyObject(int y) :m_y(y) { // It’s a good idea to assert your arguments assert(y > 0); } MyObject::~MyObject() { } Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
19.
CS 342: Intro
to C++ Programming C++ string Class #include <iostream> • <string> header file #include <string> using namespace std; • Various constructors int main() { – Prata, pp. 780 string s; // empty • Assignment operator s = “”; // empty • Overloaded operators s = “hello”; += + < >= == [] s += “, ”; s = s + “world!”; • The last one is really cout << s << endl; useful: indexes string return 0; if (s[0] == ‘h’) … } Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
20.
CS 342: Intro
to C++ Programming C++ Input/Output Stream Classes #include <iostream> • <iostream> header file using namespace std; – Use istream for input – Use ostream for output int main() { • Overloaded operators int i; << ostream insertion operator // cout == std ostream >> istream extraction operator cout << “how many?” • Other methods << endl; – ostream: write, put // cin == std istream – istream: get, eof, good, clear cin >> i; • Stream manipulators – ostream: flush, endl, setwidth, cout << “You said ” << i setprecision, hex, boolalpha << ‘.’ << endl; – Prata pp. 891-892 return 0; } Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
21.
CS 342: Intro
to C++ Programming C++ File I/O Stream Classes #include <fstream> • <fstream> header file using namespace std; – Use ifstream for input int main() { – Use ofstream for output ifstream ifs; ifs.open(“in.txt”); • Other methods ofstream ofs(“out.txt”); – open, is_open, close if (ifs.is_open() && – getline ofs.is_open()) { – seekg, seekp int i; • File modes ifs >> i; – in, out, ate, app, trunc, binary ofs << i; } ifs.close(); ofs.close(); return 0; } Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
22.
CS 342: Intro
to C++ Programming C++ String Stream Classes #include <iostream> • <sstream> header file #include <fstream> – Use istringstream for input #include <sstream> – Use ostringstream for output using namespace std; • Useful for scanning input int main() { – Get a line from file into string ifstream ifs(“in.txt”); – Wrap string in a stream if (ifs.is_open()) { – Pull words off the stream string line1, word1; • Useful for formatting output getline(ifs, line1); – Use string as format buffer istringstream iss(line1); – Wrap string in a stream iss >> word1; – Push formatted values into cout << word1 << endl; stream } – Output formatted string to file return 0; } Copyright © 2004 Dept. of Computer Science and Engineering, Washington University
Baixar agora