Showing posts with label NavidPlus. Show all posts
Showing posts with label NavidPlus. Show all posts

Thursday, March 16, 2017

C++ Part 28

Strings


A char literal is indicated with single quotes (e.g., ’c’), while a string literal is indicated with double quotes (e.g., “abc”).
These are C++ strings and are in library:
  • =: Assignment
  • <,> , <=, >= ,== , ! =, . . .:
  • s[i]: Indexing, i.e., i’th character of s (i ≥ 0)
    •  Ex: string s = ‘‘cat’’; char c = s[2] sets c to ’t’
  •  + :  Concatenation (overloaded for characters)
    • Ex: ‘‘apple’’ + ‘‘pear’’ evaluates to “applepear” while ‘‘apple’’+’s’ evaluates to “apples”
  • s.empty(): true if s is an empty string 
  • s.length(): length of s (≥ 0) 
//Assignment and comparison operators work for strings but NOT
for all C++ data types.

<<, >> : input/output (still uses whitespace as delimiter).
e.g., cin >> s1 >> s2 would assign “Navid” to s1 and “Plus” to s2,
if the user typed “Navid Plus”.

Wednesday, March 15, 2017

C++ Part 26

Void Functions

A void function performs some action, but does not return a value. For a void function, a function
invocation (function call) is a statement that can be used like any other C++ statement.

Example :

// void function example by NavidPlus.BlogSpot.com
#include <iostream>
using namespace std;

void printmessage ()
{
 cout << "This message is created by NavidPlus!";
}

int main ()
{
 printmessage ();
}



Saturday, March 11, 2017

Intro to C++ Part 6

A Sample C++ Program  


##include <iostream>
using namespace std;The following line says that main is a function with no parameters that returns an int(integer) value:int main( )Some compilers will allow you to omit the int or replace it with void, which indicates
a function that does not return a value. However, the previous form is the most
universally accepted way to start the 
main function of a C++ program.
The program ends when the following statement is executed:
return 0;  


Digital Design Part 3

4th→ assembler translates it to the machine language. 1.6 [20] <§1.6> Consider two different implementations of the same instru...