Software Development -2
C++
Letsss continueee
Increment and Decrement Operators
Let's first consider the concept of the operator. We use operators to perform arithmetic operations on data, to change the data by performing logical operations, to obtain new data from two data, and to compare data.
At the beginning of writing the code, we used the assignment operator ‘=’ which means that the specified variable is equal to the given variable.
Afterward, the arithmetic, that is, mathematical operations used for mathematical operations “-,+,+,/,*,%” are as follows respectively.
The operators we use for standard mathematical operations are seen in the table.
Today, we will see the increment and decrement operators, namely “++” and “ — “. Understanding their logic will be useful for us in for loops and in the following sections. These operators can be placed to the right and left of the variables, and the working logic changes according to where it is placed.
Application //Please make and write many examples
++X: first increment x by 1, then use the variable x with the new value.
X++:first use the value of x, then increase x by 1 after the operation.
— X: first decrease x by 1, then use the variable x with its new value.
X —: first use the value of x, then decrease x by 1.
—
#include <iostream>
using namespace std;
int main() {
int a = 5;
++a;
cout << a;
return 0;
}
—
int main() {
int a = 5;
a — ;
cout << a;
return 0;
}
—
int main(){
int a;
a = 5;
int b = ++a;
int c = b+++;
cout<<”b:” <<b<<endl;
cout<<”c:”<<c<<endl;
cout<<”a:”<<a;
return 0;
}
*** Try and comment the code for the results of the above sample application and comment them below.
STRING DATA TYPE
In C, string values are enclosed in double quotes (“”). There is no type called ‘string’ in C++. The ‘string’ type is created by the compiler using multiple character constants, i.e. the char index, as a character array.
In string expressions, a few functions and spellings to find index information in arrays are as follows;
1-Sizeof(variable): shows the value that the string value occupies in Ram. String expressions occupied 8 bytes in memory, and in the first lessons, we said that the C++ programming language is a programming language with memory management and is one of its most important features.
Sizeof(ad[0])<<”byte”;
The value of ad[0] is char. Since each word [0] starts from the first, that is zero in the software, the zeroth value refers to a single expression, that is, char. It will write like “A” and this will be shown as 1 byte in memory.
2-getline(cin, variable,”.”) function: we can use it for long texts. It takes 3 parameters. Let’s see it in practice
Application
int main()
{
string name, surname,address;
cout<<”enter your name: “<<endl;
getline(cin,name);
//cin>>name;
Get Ceren Ağım’s stories in your inbox
Join Medium for free to get updates from this writer.
cout<<” enter your last name: “<<endl;
getline(cin,surname);
//cin>>surname;
cout<<”Enter your address: “<<endl;
getline(cin,address);
//cin>>address;
cout<<”*****Informations*****”<<”\n”;
cout<<”first and last name:”<<name<<surname<<”\n”;
cout<<”address: “<<address;
return 0;
}
If you try this example, you will see that when it was done with “cin “, it did not detect it as a space and wrote it by combining long texts. For this reason, we wrote “cin” with getline() to get data, and we specified the data it received as “name” to save it here. Our biggest advantage is that it detects all long texts even if they are spaces in getline().
— — — — — — — — — — — — — — — — — — — — — — — -
Additional information = Knowledge of the expression “Const”
We use it to store constant values in const ram.
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — -
DECISION STRUCTURES
IF COMMAND
IF-ELSE IF-ELSE
IF is one of the most used query or branching commands. If the condition given to the command is met, the branching continues and the comparison and condition structures use the if structure.
If — Else ;
In the if-else query, if the condition is met, a certain command or commands are executed. If the condition is not met, another command or commands are provided.
The difference between if and if else is that if only works if the condition is met.
Else if; this housing is checked in case there is more than one condition.( If -else commands check only one condition.)
Application-1
//find out whether the entered number is odd or even
int main()
{
int number;
cout<<” enter a number:”;
cin>>number;
if ( number % 2 == 0)
cout<<” number is even”;
else
cout<<” number is odd”;
return 0;
}
Application-2
//Write an example that checks if the number is negative or positive.
int main()
{
int number= 0;
if( number< 0 )
cout<<” negative:”;
else if (number == 0)
cout<< “zero”;
else
cout<<”positive”;
return 0;
}
Application-3-
//As homework
//Save a password to the system in a fixed variable
ask for the password at application startup and if it is the same as in the system
type “login successful” and ask for a number, if the password is incorrect give a warning “You entered the wrong password”.
whether the number entered is even or odd and positive or negative
Make an application that tells the situation//
Work hard, like it 😊
You can write to me and comment on the answer to the homework…..










