1) The document provides an overview of C++ basics including variables, data types, input/output, arithmetic operators, and comments. It discusses variable naming, declarations, initialization, and assignment.
2) Key data types discussed include integers, floating-point numbers, characters, Booleans, and strings. The string class allows strings to be manipulated similarly to other data types.
3) Input is handled with cin and output with cout. Escape sequences can be used to control formatting. Arithmetic operators allow expressions to be formed. Comments start with // and /* */.
The document provides an introduction to programming fundamentals in C++, including basic syntax and components of a C++ program. It covers variables and data types, input/output, comments, and how to write a simple C++ program with preprocessor directives and a main function. The key topics discussed are variable declaration, fundamental data types like int, float, char, comments, and how to write a basic "Hello World" program in C++.
This document discusses basic program elements in C++, including:
1. Initializing variables can be done in two ways - by appending an equal sign followed by the value (int a = 0), or by enclosing the value in parentheses (int a(0)). Both methods are valid in C++.
2. Variables can have either local or global scope - local variables are declared within a function while global variables are declared outside all functions.
3. Keywords are reserved words in C++ that have special meaning and cannot be used as regular identifiers. Common keywords include int, float, if, else, while, etc.
02a fundamental c++ types, arithmetic Manzoor ALam
油
The document discusses fundamental C++ types including integers, characters, and floating-point numbers. It describes integer types like int, short, and long and their typical sizes. Character types represent single characters with examples of escape codes. Floating-point types can represent real numbers in formats like float and double. The document also covers C++ concepts such as variable definitions and declarations, arithmetic operators, assignment, and increment/decrement operators.
The document discusses various C++ programming concepts including variables, data types, input/output streams, and expressions. It defines variables as memory locations that can store values, and describes different data types like int, double, char. It also covers input with cin, output with cout, and formatting output values.
The document provides information on fundamental C data types including bits, bytes, words, integers, floating point numbers, enumerated types, variables, type conversions, constants, and basic operators. It defines common data types like char, int, float, and double. It also covers typecasting, variable declaration, and basic arithmetic, logical, relational, and bitwise operators.
This document provides an introduction to the C programming language. It discusses that C was developed in 1972 by Dennis Ritchie at Bell Labs to create the UNIX operating system. C is a structured, procedural programming language that is widely used to develop operating systems, databases, networks, and more. The document then covers some key concepts in C including functions, header files, variables, data types, operators, and escape sequences. It provides examples of basic C programs and exercises for practicing programming concepts.
C++ variables can hold different data types like numbers and characters. Variables must be declared with a name and type before use and can be assigned values. Keywords like int and double are used to declare variable types for whole numbers and decimals. Variables are output using cout and input using cin. User input and output allows the program to display prompts and receive user-entered values.
C++ Basics discusses variables, identifiers, keywords, variable declarations, assignment, output, input, and escape sequences in C++. Key points include:
- Variables hold data in memory locations labeled with their name. Common types are int for whole numbers and double for fractional numbers.
- Identifiers name variables and must start with a letter or underscore. Keywords are reserved for language use.
- Variables must be declared before use, specifying their type and name. They can be declared at the beginning or close to use.
- Assignment sets a variable's value using the = operator. Output streams like cout send data to the screen. Input streams like cin get data from the user.
The aim of this list of programming languages is to include all notable programming languages in existence, both those in current use and ... Note: This page does not list esoteric programming languages. .... Computer programming portal ...
The document provides an introduction to the C++ programming language, including its history, characteristics, and components. It notes that C++ was created in the 1980s by Bjarne Stroustrup at Bell Labs as an enhancement to the C language that added object-oriented programming capabilities while still maintaining efficiency. Some key characteristics of C++ include object-oriented programming, portability, modular programming, C compatibility, and a wide range of library functions. The document discusses the basic building blocks of C++, including tokens like identifiers, keywords, constants, punctuators, and operators.
C++ Basics introduces variables, identifiers, assignments, and input/output. Variables hold data of a specified type and are accessed by name. Identifiers name variables and follow specific naming rules. Variables are declared with a type and can be assigned values. Output streams like cout display data, while input streams like cin get user input assigned to variables. Escape sequences represent special characters in output.
C++ Basics introduces variables, identifiers, assignments, and input/output. Variables hold data of a specified type and are accessed by name. Identifiers name variables and follow specific naming rules. Variables are declared with a type and can be assigned values. Output streams like cout display data, while input streams like cin get user input assigned to variables. Escape sequences represent special characters in output.
#Code2Create series: C++ is a powerful general-purpose programming language. It can be used to develop operating systems, browsers, games, and so on. C++ supports different ways of programming like procedural, object-oriented, functional, and so on.Start your programming journey and join us to learn C++ basics!
by Google Developers Group and Women Tech-markers Kuwait chapter:
Instagram and Twitter: @GDGWTMKUWAIT
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubeykiranrajat
油
The document provides an overview of fundamentals of C programming including data types, identifiers, operators, input/output, type casting, precedence rules, variables scope, and preprocessors. It discusses basic data types in C like integer, floating point, and their sizes. It also covers C identifiers naming rules, keywords, arithmetic, relational, and logical operators along with their precedence.
The document provides an introduction to the C programming language. It discusses the structure of a C program including documentation, preprocessor directives, header files, and function definitions. It also describes various math and trigonometric functions available in the standard library like sqrt, pow, sin, cos, and log. The rest of the document outlines the steps to compile and execute a C program and defines key concepts like variables, constants, and data types in C.
This document discusses various data types in C programming language. It begins by defining what a data type is and then provides examples of common data types like char, int, float, and double. It explains that each data type requires a different amount of memory and has an associated range for storing values. The document then provides a table listing the typical ranges and memory requirements for each data type on a 32-bit compiler. It also includes an example C program demonstrating the usage of different data types.
The document provides an overview of key concepts in C programming including comments, header files, character sets, tokens, keywords, constants, data types, and special symbols. It discusses various types of comments, the purpose of header files, the basic character set in C, different types of tokens, common keywords like auto, break, const, continue, and their usage. It also explains integer, character, string, and backslash constants as well as basic and special data types.
This document summarizes key concepts from an introduction to C++ programming chapter, including:
- The main parts of a C++ program are comments, preprocessor directives, the main() function, and statements.
- Variables are used to store and manipulate data in a program. Variables are declared with a name and type before use.
- Arithmetic operators allow performing calculations in C++ programs. Expressions follow order of operations rules.
- Input and output streams allow getting user input and displaying output to the screen.
C++ variables can hold different data types like numbers and characters. Variables must be declared with a name and type before use and can be assigned values. Keywords like int and double are used to declare variable types for whole numbers and decimals. Variables are output using cout and input using cin. User input and output allows the program to display prompts and receive user-entered values.
C++ Basics discusses variables, identifiers, keywords, variable declarations, assignment, output, input, and escape sequences in C++. Key points include:
- Variables hold data in memory locations labeled with their name. Common types are int for whole numbers and double for fractional numbers.
- Identifiers name variables and must start with a letter or underscore. Keywords are reserved for language use.
- Variables must be declared before use, specifying their type and name. They can be declared at the beginning or close to use.
- Assignment sets a variable's value using the = operator. Output streams like cout send data to the screen. Input streams like cin get data from the user.
The aim of this list of programming languages is to include all notable programming languages in existence, both those in current use and ... Note: This page does not list esoteric programming languages. .... Computer programming portal ...
The document provides an introduction to the C++ programming language, including its history, characteristics, and components. It notes that C++ was created in the 1980s by Bjarne Stroustrup at Bell Labs as an enhancement to the C language that added object-oriented programming capabilities while still maintaining efficiency. Some key characteristics of C++ include object-oriented programming, portability, modular programming, C compatibility, and a wide range of library functions. The document discusses the basic building blocks of C++, including tokens like identifiers, keywords, constants, punctuators, and operators.
C++ Basics introduces variables, identifiers, assignments, and input/output. Variables hold data of a specified type and are accessed by name. Identifiers name variables and follow specific naming rules. Variables are declared with a type and can be assigned values. Output streams like cout display data, while input streams like cin get user input assigned to variables. Escape sequences represent special characters in output.
C++ Basics introduces variables, identifiers, assignments, and input/output. Variables hold data of a specified type and are accessed by name. Identifiers name variables and follow specific naming rules. Variables are declared with a type and can be assigned values. Output streams like cout display data, while input streams like cin get user input assigned to variables. Escape sequences represent special characters in output.
#Code2Create series: C++ is a powerful general-purpose programming language. It can be used to develop operating systems, browsers, games, and so on. C++ supports different ways of programming like procedural, object-oriented, functional, and so on.Start your programming journey and join us to learn C++ basics!
by Google Developers Group and Women Tech-markers Kuwait chapter:
Instagram and Twitter: @GDGWTMKUWAIT
MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubeykiranrajat
油
The document provides an overview of fundamentals of C programming including data types, identifiers, operators, input/output, type casting, precedence rules, variables scope, and preprocessors. It discusses basic data types in C like integer, floating point, and their sizes. It also covers C identifiers naming rules, keywords, arithmetic, relational, and logical operators along with their precedence.
The document provides an introduction to the C programming language. It discusses the structure of a C program including documentation, preprocessor directives, header files, and function definitions. It also describes various math and trigonometric functions available in the standard library like sqrt, pow, sin, cos, and log. The rest of the document outlines the steps to compile and execute a C program and defines key concepts like variables, constants, and data types in C.
This document discusses various data types in C programming language. It begins by defining what a data type is and then provides examples of common data types like char, int, float, and double. It explains that each data type requires a different amount of memory and has an associated range for storing values. The document then provides a table listing the typical ranges and memory requirements for each data type on a 32-bit compiler. It also includes an example C program demonstrating the usage of different data types.
The document provides an overview of key concepts in C programming including comments, header files, character sets, tokens, keywords, constants, data types, and special symbols. It discusses various types of comments, the purpose of header files, the basic character set in C, different types of tokens, common keywords like auto, break, const, continue, and their usage. It also explains integer, character, string, and backslash constants as well as basic and special data types.
This document summarizes key concepts from an introduction to C++ programming chapter, including:
- The main parts of a C++ program are comments, preprocessor directives, the main() function, and statements.
- Variables are used to store and manipulate data in a program. Variables are declared with a name and type before use.
- Arithmetic operators allow performing calculations in C++ programs. Expressions follow order of operations rules.
- Input and output streams allow getting user input and displaying output to the screen.
Viceroys of India & Their Tenure Key Events During British RuleDeeptiKumari61
油
The British Raj in India (1857-1947) saw significant events under various Viceroys, shaping the political, economic, and social landscape.
**Early Period (1856-1888):**
Lord Canning (1856-1862) handled the Revolt of 1857, leading to the British Crown taking direct control. Universities were established, and the Indian Councils Act (1861) was passed. Lord Lawrence (1864-1869) led the Bhutan War and established High Courts. Lord Lytton (1876-1880) enforced repressive laws like the Vernacular Press Act (1878) and Arms Act (1878) while waging the Second Afghan War.
**Reforms & Political Awakening (1880-1905):**
Lord Ripon (1880-1884) introduced the Factory Act (1881), Local Self-Government Resolution (1882), and repealed the Vernacular Press Act. Lord Dufferin (1884-1888) oversaw the formation of the Indian National Congress (1885). Lord Lansdowne (1888-1894) passed the Factory Act (1891) and Indian Councils Act (1892). Lord Curzon (1899-1905) introduced educational reforms but faced backlash for the Partition of Bengal (1905).
**Rise of Nationalism (1905-1931):**
Lord Minto II (1905-1910) saw the rise of the Swadeshi Movement and the Muslim League's formation (1906). Lord Hardinge II (1910-1916) annulled Bengals Partition (1911) and shifted Indias capital to Delhi. Lord Chelmsford (1916-1921) faced the Lucknow Pact (1916), Jallianwala Bagh Massacre (1919), and Non-Cooperation Movement. Lord Reading (1921-1926) dealt with the Chauri Chaura Incident (1922) and the formation of the Swaraj Party. Lord Irwin (1926-1931) saw the Simon Commission protests, the Dandi March, and the Gandhi-Irwin Pact (1931).
**Towards Independence (1931-1947):**
Lord Willingdon (1931-1936) introduced the Government of India Act (1935), laying India's federal framework. Lord Linlithgow (1936-1944) faced WWII-related crises, including the Quit India Movement (1942). Lord Wavell (1944-1947) proposed the Cabinet Mission Plan (1946) and negotiated British withdrawal. Lord Mountbatten (1947-1948) oversaw India's Partition and Independence on August 15, 1947.
**Final Transition:**
C. Rajagopalachari (1948-1950), Indias last Governor-General, facilitated Indias transition into a republic before the position was abolished in 1950.
The British Viceroys played a crucial role in Indias colonial history, introducing both repressive and progressive policies that fueled nationalist movements, ultimately leading to independence.https://www.youtube.com/@DKDEducation
Enhancing SoTL through Generative AI -- Opportunities and Ethical Considerati...Sue Beckingham
油
This presentation explores the role of generative AI (GenAI) in enhancing the Scholarship of Teaching and Learning (SoTL), using Feltens five principles of good practice as a guiding framework. As educators within higher education institutions increasingly integrate GenAI into teaching and research, it is vital to consider how these tools can support scholarly inquiry into student learning, while remaining contextually grounded, methodologically rigorous, collaborative, and appropriately public.
Through practical examples and case-based scenarios, the session demonstrates how generative GenAI can assist in analysing critical reflection of current practice, enhancing teaching approaches and learning materials, supporting SoTL research design, fostering student partnerships, and amplifying the reach of scholarly outputs. Attendees will gain insights into ethical considerations, opportunities, and limitations of GenAI in SoTL, as well as ideas for integrating GenAI tools into their own scholarly teaching practices. The session invites critical reflection and dialogue about the responsible use of GenAI to enhance teaching, learning, and scholarly impact.
Stages of combustion, Ignition lag, Flame propagation, Factors affecting flame
speed, Abnormal combustion, Influence of engine design and operating
variables on detonation, Fuel rating, Octane number, Fuel additives, HUCR,
Requirements of combustion chambers of S.I. Engines and its types.
Measles OutbreakSouthwestern US This briefing reviews the current situation surrounding the measles outbreaks in Texas, New Mexico, Oklahoma, and Kansas.
Different perspectives on dugout canoe heritage of Soomaa.pdfAivar Ruukel
油
Sharing the story of haabjas to 1st-year students of the University of Tartu MA programme "Folkloristics and Applied Heritage Studies" and 1st-year students of the Erasmus Mundus Joint Master programme "Education in Museums & Heritage".
General College Quiz conducted by Pragya the Official Quiz Club of the University of Engineering and Management Kolkata in collaboration with Ecstasia the official cultural fest of the University of Engineering and Management Kolkata.
Relive the excitement of the Sports Quiz conducted as part of the prestigious Quizzitch Cup 2025 at NIT Durgapur! Organized by QuizINC, the official quizzing club, this quiz challenged students with some of the most thrilling and thought-provoking sports trivia.
Whats Inside?
A diverse mix of questions across multiple sports Cricket, Football, Olympics, Formula 1, Tennis, and more!
Challenging and unique trivia from historic moments to recent sporting events
Engaging visuals and fact-based questions to test your sports knowledge
Designed for sports enthusiasts, quiz lovers, and competitive minds
Students, sports fans, and quizzers looking for an exciting challenge
College quizzing clubs and organizers seeking inspiration for their own sports quizzes
Trivia buffs and general knowledge enthusiasts who love sports-related facts
Quizzing is more than just answering questionsits about learning, strategizing, and competing. This quiz was crafted to challenge even the sharpest minds and celebrate the world of sports with intellect and passion!
Different Facets of Knowledge on different View.pptxNrapendraVirSingh
油
Knowledge is a fundamental aspect of human understanding, evolving through different dimensions and perspectives. The nature of knowledge varies depending on its scope, application, and contextual relevance. In this lecture, we explore four key distinctions in knowledge: Particular vs. Universal, Concrete vs. Abstract, Practical vs. Theoretical, and Textual vs. Contextual. Each of these dichotomies helps us comprehend how knowledge is categorized, interpreted, and applied across different fields of study.
General Quiz at ChakraView 2025 | Amlan Sarkar | Ashoka Univeristy | Prelims ...Amlan Sarkar
油
Prelims (with answers) + Finals of a general quiz originally conducted on 9th February, 2025.
This was the closing quiz of the 2025 edition of ChakraView - the annual quiz fest of Ashoka University.
Feedback welcome at amlansarkr@gmail.com
CLEFT LIP AND PALATE: NURSING MANAGEMENT.pptxPRADEEP ABOTHU
油
Cleft lip, also known as cheiloschisis, is a congenital deformity characterized by a split or opening in the upper lip due to the failure of fusion of the maxillary processes. Cleft lip can be unilateral or bilateral and may occur along with cleft palate. Cleft palate, also known as palatoschisis, is a congenital condition characterized by an opening in the roof of the mouth caused by the failure of fusion of the palatine processes. This condition can involve the hard palate, soft palate, or both.
Unit No 4- Chemotherapy of Malignancy.pptxAshish Umale
油
In the Pharmacy profession there are many dangerous diseases from which the most dangerous is cancer. Here we study about the cancer as well as its treatment that is supportive to the students of semester VI of Bachelor of Pharmacy. Cancer is a disease of cells of characterized by Progressive, Persistent, Perverted (abnormal), Purposeless and uncontrolled Proliferation of tissues. There are many types of cancer that are harmful to the human body which are responsible to cause the disease condition. The position 7 of guanine residues in DNA is especially susceptible. Cyclophosphamide is a prodrug converted to the active metabolite aldophosphamide in the liver. Procarbazine is a weak MAO inhibitor; produces sedation and other CNS effects, and can interact with foods and drugs. Methotrexate is one of the most commonly used anticancer drugs. Methotrexate (MTX) is a folic acid antagonist. 6-MP and 6-TG are activated to their ribonucleotides, which inhibit purine ring biosynthesis and nucleotide inter conversion. Pyrimidine analogue used in antineoplastic, antifungal and anti psoriatic agents.
5-Fluorouracil (5-FU) is a pyrimidine analog. It is a complex diterpin taxane obtained from bark of the Western yew tree. Actinomycin D is obtained from the fungus of Streptomyces species. Gefitinib and Erlotinib inhibit epidermal growth factor receptor (EGFR) tyrosine kinase. Sunitinib inhibits multiple receptor tyrosine kinases like platelet derived growth factor (PDGF) Rituximab target antigen on the B cells causing lysis of these cells.
Prednisolone is 4 times more potent than hydrocortisone, also more selective glucocorticoid, but fluid retention does occur with high doses. Estradiol is a major regulator of growth for the subset of breast cancers that express the estrogen receptor (ER, ESR1).
Finasteride and dutasteride inhibit conversion of testosterone to dihydrotestosterone in prostate (and other tissues), have palliative effect in advanced carcinoma prostate; occasionally used. Chemotherapy in most cancers (except curable cancers) is generally palliative and suppressive. Chemotherapy is just one of the modes in the treatment of cancer. Other modes like radiotherapy and surgery are also employed to ensure 'total cell kill'.
How to Install Odoo 18 with Pycharm - Odoo 18 際際滷sCeline George
油
In this slide well discuss the installation of odoo 18 with pycharm. Odoo 18 is a powerful business management software known for its enhanced features and ability to streamline operations. Built with Python 3.10+ for the backend and PostgreSQL as its database, it provides a reliable and efficient system.
Pass SAP C_C4H47_2503 in 2025 | Latest Exam Questions & Study MaterialJenny408767
油
Pass SAP C_C4H47_2503 with expert-designed practice tests & real questions. Start preparing today with ERPPrep.com and boost your SAP Sales Cloud career!
Chapter 6. Business and Corporate Strategy Formulation.pdfRommel Regala
油
This integrative course examines the strategic decision-making processes of top management,
focusing on the formulation, implementation, and evaluation of corporate strategies and policies.
Students will develop critical thinking and analytical skills by applying strategic frameworks,
conducting industry and environmental analyses, and exploring competitive positioning. Key
topics include corporate governance, business ethics, competitive advantage, and strategy
execution. Through case studies and real-world applications, students will gain a holistic
understanding of strategic management and its role in organizational success, preparing them to
navigate complex business environments and drive strategic initiatives effectively.
2. 2
// Sample program
// Reads values for the length and width of a rectangle
// and returns the perimeter and area of the rectangle.
#include <iostream.h>
void main()
{
int length, width;
int perimeter, area; // declarations
cout << "Length = "; // prompt user
cin >> length; // enter length
cout << "Width = "; // prompt user
cin >> width; // input width
perimeter = 2*(length+width); // compute perimeter
area = length*width; // compute area
cout << endl
<< "Perimeter is " << perimeter;
cout << endl
<< "Area is " << area
<< endl; // output results
} // end of main program
3. 3
The following points should be
The following points should be
noted in the above program:
noted in the above program:
Any text from the symbols // until
the end of the line is ignored by the
compiler.
The line #include <iostream.h>
This statement is a compiler directive
-- that is it gives information to the
compiler but does not cause any
executable code to be produced.
4. 4
The following points should be
The following points should be
noted in the above program:
noted in the above program:
The actual program consists of the
function main which commences at
the line void main() All programs
must have a function main.
The body of the function main
contains the actual code which is
executed by the computer and is
enclosed, as noted above, in braces
{}.
5. 5
The following points should be
The following points should be
noted in the above program:
noted in the above program:
Every statement which instructs the
computer to do something is
terminated by a semi-colon ;.
Sequences of characters enclosed in
double quotes are literal strings.
Thus instructions such as
cout << "Length = "
send the quoted characters to the output stream cout.
6. 6
The following points should be
The following points should be
noted in the above program:
noted in the above program:
All variables that are used in a program
must be declared and given a type. In this
case all the variables are of type int, i.e.
whole numbers. Thus the statement
int length, width;
Values can be given to variables by the
assignment statement, e.g. the statement
area = length*width;
7. 7
The following points should be
The following points should be
noted in the above program:
noted in the above program:
Layout of the program is quite
arbitrary, i.e. new lines, spaces etc.
can be inserted wherever desired
and will be ignored by the compiler.
8. 8
Variables
Variables
A variable is the name used for the
quantities which are manipulated by
a computer program.
In order to distinguish between
different variables, they must be
given identifiers, names which
distinguish them from all other
variables.
9. 9
The rules of C++ for
The rules of C++ for
valid identifiers
valid identifiers
An identifier must:
start with a letter
consist only of letters, the digits 0-9, or
the underscore symbol _
not be a reserved word
Reserved words are otherwise valid identifiers that
have special significance to C++.
use of two consecutive underscore
symbols, __, is forbidden.
10. 10
Identifiers
Identifiers
The following are valid identifiers
Length days_in_year DataSet1
Profit95 Int_Pressure
first_one first_1
although using _Pressure is not
recommended.
The following are invalid:
days-in-year 1data
int first.val throw
11. 11
Identifiers
Identifiers
Identifiers should be meaningful
C++ is case-sensitive. That is lower-
case letters are treated as distinct
from upper-case letters.
Thus the word main in a program is
quite different from the word Main or
the word MAIN.
12. 12
Reserved words
Reserved words
and and_eq asm auto bitand
bitor bool break case catch
char class const const_cast continue
default delete do double dynamic_cast
else enum explicit export extern
false float for friend goto
if inline int long mutable
namespace new not not_eq operator
or or_eq private protected public
register reinterpret_cast return short signed
sizeof static static_cast struct switch
template this throw true try
typedef typeid typename union unsigned
using virtual void volatile wchar_t
while xor xor_eq
13. 13
Declaration of variables
Declaration of variables
In C++ all the variables that a program is
going to use must be declared prior to
use.
Declaration of a variable serves two
purposes:
It associates a type and an identifier (or name)
with the variable. The type allows the compiler
to interpret statements correctly.
It allows the compiler to decide how much
storage space to allocate for storage of the
value associated with the identifier and to
assign an address for each variable which can
be used in code generation.
15. 15
int
int
int variables can represent negative and positive
integer values (whole numbers).
There is a limit on the size of value that can be
represented, which depends on the number of
bytes of storage allocated to an int variable by
the computer system and compiler being used.
On a PC most compilers allocate two bytes for
each int which gives a range of -32768 to
+32767.
On workstations, four bytes are usually allocated,
giving a range of -2147483648 to 2147483647.
It is important to note that integers are
represented exactly in computer memory.
16. 16
float
float
float variables can represent any real numeric
value, that is both whole numbers and numbers
that require digits after the decimal point.
The accuracy and the range of numbers
represented is dependent on the computer
system.
Usually four bytes are allocated for float
variables, this gives an accuracy of about six
significant figures and a range of about -1038
to
+1038
.
It is important to note that float values are only
represented approximately.
17. 17
bool
bool
bool variables can only hold the
values true or false.
These variables are known as
boolean variables in honour of
George Boole, an Irish
mathematician who invented boolean
algebra.
18. 18
char
char
char variables represent a single
character -- a letter, a digit or a
punctuation character.
They usually occupy one byte, giving
256 different possible characters.
The bit patterns for characters
usually conform to the American
Standard Code for Information
Interchange (ASCII).
19. 19
Examples of values for such
Examples of values for such
variables are:
variables are:
int 123 -56 0 5645
float 16.315 -0.67 31.567
char '+' 'A' 'a' '*' '7'
20. 20
Variable Declarations
Variable Declarations
A typical set of variable declarations that
might appear at the beginning of a
program could be as follows:
int i, j, count;
float sum, product;
char ch;
bool passed_exam;
which declares integer variables i, j and
count, real variables sum and product, a
character variable ch, and a boolean
variable pass_exam.
21. 21
A variable declaration has
A variable declaration has
the form:
the form:
type identifier-list;
Type specifies the type of the variables
being declared.
The identifier-list is a list of the identifiers
of the variables being declared, separated
by commas
Variables may be initialized at the time of
declaration by assigning a value to them
23. 23
Constants and the
Constants and the
declaration of constants
declaration of constants
Often in programming numerical constants
are used, e.g. the value of 其.
It is well worthwhile to associate
meaningful names with constants.
These names can be associated with the
appropriate numerical value in a constant
declaration.
The names given to constants must
conform to the rules for the formation of
identifiers as defined above.
24. 24
Constants and the
Constants and the
declaration of constants
declaration of constants
const int days_in_year = 365;
defines an integer constant days_in_year which has the
value 365.
Later in the program the identifier days_in_year can be
used instead of the integer 365, making the program far
more readable.
The general form of a constant declaration is:
const type constant-identifier = value ;
25. 25
General form of a C++
General form of a C++
Program
Program
// Introductory comments
// file name, programmer, when written or modified
// what program does
#include <iostream.h>
void main()
{
constant declarations
variable declarations
executable statements
}
26. 26
Input and Output
Input and Output
Input and output use the input
stream cin and the output stream
cout.
The input stream cin is usually
associated with the keyboard
The output stream cout is usually
associated with the monitor.
27. 27
cin
cin
The following statement waits for a number to be
entered from the keyboard and assigns it to the
variable number:
cin >> number;
The general form of a statement to perform input
using the input stream cin is:
cin input-list;
where input-list is a list of identifiers, each identifier
preceded by the input operator >>.
28. 28
cin
cin
cin >> n1 >> n2;
would take the next two values entered by the user and
assign the value of the first one to the variable n1 and the
second to the variable n2.
User enter
10 20 <ENTER>
10 <ENTER>
20<ENTER>
10 20 30 <ENTER>
29. 29
cout
cout
The following statement outputs the current value
of the variable count to the output stream cout
cout << count;
The general form of a statement to perform
output using the output stream cout is:
cout output-list;
where output-list is a list of variables, constants, or
character strings in quotation marks, each
preceded by the output operator <<.
30. 30
cout
cout
cout << "Hello there" << endl;
will print Hello there on the current
output line and then take a new line
for the next output.
31. 31
Example
Example
float length, breadth;
cout << "Enter the length and breadth: ";
cin >> length >> breadth;
cout << endl << "The length is " << length;
cout << endl << "The breadth is " << breadth << endl;
will display, if the user enters 6.51 and 3.24 at the
prompt, the following output:
The length is 6.51
The breadth is 3.24
32. 32
Example
Example
Note that a value written to cout will be printed
immediately after any previous value with no
space between.
In the above program the character strings
written to cout each end with a space character.
The statement
cout << length << breadth;
would print out the results as 6.513.24
which is obviously impossible to interpret
correctly. If printing several values on the same
line remember to separate them with spaces by
printing a string in between them as follows:
cout << length << " " << breadth;
33. 33
Programming Style
Programming Style
any number of spaces and or new
lines can be used to separate the
different symbols in a C++ program.
The identifiers chosen for variables
mean nothing to the compiler either,
but using identifiers which have
some significance to the programmer
is good practice.
34. 34
Programming Style
Programming Style
The program below is identical to the
original example in this Lesson,
except for its layout and the
identifiers chosen. Which program
would you rather be given to modify?
35. 35
Programming Style
Programming Style
#include <iostream.h>
void main(
) { int a,b,
c,d; cout << "Length = "; cin >> a;
cout<<"Width = "
;cin >> b; c = 2*(a+
b); d = a*b; cout
<< endl << "Perimeter is " <<
c << endl << "Area is " << d
<< endl;}
36. 36
Summary
Summary
All C++ programs must include a function main().
All executable statements in C++ are terminated
by a semi-colon.
Comments are ignored by the compiler but are
there for the information of someone reading the
program. All characters between // and the end of
the line are ignored by the compiler.
All variables and constants that are used in a C++
program must be declared before use. Declaration
associates a type and an identifier with a variable.
The type int is used for whole numbers which are
represented exactly within the computer.
37. 37
Summary
Summary
The type float is used for real (decimal) numbers. They are
held to a limited accuracy within the computer.
The type char is used to represent single characters. A char
constant is enclosed in single quotation marks.
Literal strings can be used in output statements and are
represented by enclosing the characters of the string in
double quotation marks ".
Variables names (identifiers) can only include letters of the
alphabet, digits and the underscore character. They must
commence with a letter.
Variables take values from input when included in input
statements using cin >> variable-identifier.
The value of a variable or constant can be output by
including the identifier in the output list cout << output-
list. Items in the output list are separated by <<.
40. 40
Exercises
Exercises 2
2
Write a program to read in four
characters and to print them out,
each one on a separate line,
enclosed in single quotation marks.
41. 41
Exercises
Exercises 3
3
Write a program which prompts the
user to enter two integer values and
a float value and then prints out the
three numbers that are entered with
a suitable message.
43. 43
The Assignment statement
The Assignment statement
The main statement in C++ for
carrying out computation and
assigning values to variables is the
assignment statement.
For example the following
average = (a + b)/2;
assigns half the sum of a and b to
the variable average.
44. 44
The Assignment statement
The Assignment statement
The general form of an assignment
statement is:
result = expression ;
The expression is evaluated and then
the value is assigned to the variable
result.
It is important to note that the value
assigned to result must be of the
same type as result.
45. 45
The expression
The expression
can be a single variable,
a single constant
variables and constants combined by
the arithmetic operators.
Rounded brackets () may also be
used in matched pairs in expressions
to indicate the order of evaluation.
46. 46
Arithmetic Operators
Arithmetic Operators
+ addition
- subtraction
* multiplication
/ division
% remainder after division (modulus)
i = 3;
sum = 0.0;
perimeter = 2.0 * (length + breadth);
ratio = (a + b)/(c + d);
47. 47
The type of the operands of
The type of the operands of
an arithmetic operator
an arithmetic operator
The following rules apply:
if both operands are of type int then the result is
of type int.
if either operand, or both, are of type float then
the result is of type float.
if the expression evaluates to type int and the
result variable is of type float then the int will be
converted to an equivalent float before
assignment to the result variable.
if the expression evaluates to type float and the
result variable is of type int then the float will be
converted to an int, usually by rounding towards
zero, before assignment to the result variable.
48. 48
Priority of Operators
Priority of Operators
a + b * c
be evaluated by performing the
multiplication first, or by performing
the addition first? i.e. as
(a + b) * c or as a + (b * c) ?
49. 49
Priority of Operators
Priority of Operators
C++ solves this problem by
assigning priorities to operators
Operators with high priority are then
evaluated before operators with low
priority.
Operators with equal priority are
evaluated in left to right order.
50. 50
Priority of Operators
Priority of Operators
The priorities of the operators seen
so far are, in high to low priority
order:
( )
* / %
+ -
=
51. 51
Priority of Operators
Priority of Operators
Thus a + b * c is evaluated as if it
had been written as a + (b * c)
because the * has a higher priority
than the +.
If in any doubt use extra brackets to
ensure the correct order of
evaluation.
52. 52
Type Conversions
Type Conversions
Division of integers will always give an
integer result.
If the correct float result is required, then
the compiler must be forced to generate
code that evaluates the expression as a
float.
If either of the operands is a constant,
then it can be expressed as a floating
point constant by appending a .0 to it, as
we have seen.
53. 53
Type Conversions
Type Conversions
To force an expression involving two
int variables to be evaluated as a
float expression, at least one of the
variables must be converted to float.
This can be done by using the cast
operation:
f = float(i)/float(n);
54. 54
Exercise
Exercise
Write a program to converts an input
value in degrees Fahrenheit to the
corresponding value in degrees
Centigrade
C = 5/9 * (F-32)
55. 55
Exercise
Exercise
Write a program to converts an input
value in pence to the equivalent
value in pounds and pence.
56. 56
Exercise
Exercise
Write a C++ program which reads
values for two floats and outputs
their sum, product and quotient.
Include a sensible input prompt and
informative output.
57. 57
Summary
Summary
Expressions are combinations of operands and
operators.
The order of evaluation of an expression is
determined by the precedence of the operators.
In an assignment statement, the expression on
the right hand side of the assignment is
evaluated and, if necessary, converted to the
type of the variable on the left hand side before
the assignment takes place.
When float expressions are assigned to int
variables there may be loss of accuracy.
59. 59
Increment and Decrement
Increment and Decrement
Operators
Operators
Some operations that occur so
frequently in writing assignment
statements that C++ has shorthand
methods for writing them.
One common situation is that of
incrementing or decrementing an
integer variable. For example:
n = n + 1;
n = n - 1;
60. 60
Increment and Decrement
Increment and Decrement
Operators
Operators
C++ has an increment operator ++
and a decrement operator --. Thus
n++; can be used instead of n = n + 1;
n--; can be used instead of n = n - 1;
++n; can be used instead of n = n + 1;
--n; can be used instead of n = n - 1;
61. 61
Increment and Decrement
Increment and Decrement
Operators
Operators
For example if n has the value 5 then
i = n++;
would set i to the original value of n i.e. 5
and would then increment n to 6.
i = ++n;
would increment n to 6 and then set i to 6.
62. 62
Specialised Assignment
Specialised Assignment
Statements
Statements
Another common situation that occurs is
assignments such as the follows:
sum = sum + x;
in which a variable is increased by some
amount and the result assigned back to
the original variable.
This type of assignment can be
represented in C++ by:
sum += x;
63. 63
Specialised Assignment
Specialised Assignment
Statements
Statements
This notation can be used with the
arithmetic operators +, -, *, / and %.
The general form of such compound
assignment operators is:
variable op= expression
which is interpreted as being equivalent to:
variable = variable op ( expression )