Recent Changes - Search:

Welcome to CAVI, the Cisco Academy for the Vision Impaired.

Course Fees Linux Wiki HTML Wiki Documentation Index PmWiki FAQ

Edit SideBar

Chapter2

Chapter 2

2.1.1

Image 1:

This image shows a more advanced conditional statement called if-else, this has been written out below in C++.

if(true_or_false_condition)
Perform_if_condition_true;  
else
perform_if_condition_false;

2.1.2

Image 1:

This image shows another example of conditional if-else statement, this is written out below in C++.

if(TheWheatherIsGood)
GoForAWalk();
else
GoToATheater();
HaveLunch(); 

2.1.3

Image 1:

This image shows another example of conditional if-else statement with a block for more than one instruction; this is written out below in C++.

if(TheWheatherIsGood){
GoForAWalk();
HaveFun();
}
else{
GoToATheater();
EnjoyTheMovie();
}
HaveLunch(); 

2.1.4

Image 1:

This image shows another example of conditional if-else statement with nesting; this is written out below in C++.

if(TheWheatherIsGood)
 if(NiceRestourantFound)
      HaveLunch();
 else
     EatASandwitch();
 else
if(TicketsAvailable)
    GoToATheatre();
 else
    GoShopping(); 

2.1.5

Image 1:

This image shows another example of conditional if-else statement with cascade; this is written out below in C++.

if(TheWheatherIsGood)
    GoForAWalk();
else if(TicketsAvailable)
    GoToATheatre();
else if(TableAvailable)
    GoForALunch();
else 
     PlayChessAtHome(); 

2.2.1

Image 1:

This image shows the int and maximum range of numbers which can be used in C++; these are written out below.

-2147483648 to 2147483647 

2.2.2

Image 1:

This image is showing the int and maximum range of numbers when the ranges of numbers are smaller, for example 16bits instead of 32bit, or 64bit instead of 32bit which means the int numbers will not be negative. The positive numbers that can be used in C++ are written out below.

0 to 4294967295

2.2.3

Image 1:

This image shows three different modifiers for C++; these are written out below.

Long, short, unsigned.

2.2.4

Image 1:

This image shows the short modifier with the counter variable in a C++ statement. This is written out below.

short int Counter;

2.2.5

Image 1:

This image shows the long modifier with the Ants variable in a C++ statement. This is written out below.

long int Ants;

2.2.6

Image 1:

This image shows the unsigned modifier in a C++ statement. This is written out below.

unsigned int postive;

2.2.7

Image 1:

This image shows two modifiers being used in a C++ code. The code has been written out below.

 
unsigned long int HugeNumber;

2.2.8

Image 1:

This image shows two modifiers being used in C++ code. The code has been written out below.

unsigned short int lambs;

2.2.9

Image 1:

This is an image of the unsigned modifier and the char variable in C++ code. This is written out below.

unsigned char LittleCounter; 

2.2.10 Image 1:

This image shows the comparison of the float variable and the double variable which has been written out below.

Float: 1111111111111111111.11111111111111111111
Double: 1111111131851653120.000000 

2.2.11

Image 1:

This image shows two float numbers added together; this has been written out below.

11111111000.0+0.00011111111

2.2.12

Image 1:

This image shows the bool variable in C++ code. This is written out below.

bool developer_is_hungry=false; 

2.3.1

Image 1:

This is an image of a complete program to identify the larger of two numbers which has been written out below in C++

/*finding the larger of two numbers*/ 
#include<iostream> 
using namespace std;

int main(void){
/*the two numbers*/
int number1,number2;

/*we will save the larger numbers here*/
int max

/*read two numbers*/ 
cin>>number1;
cin>>number2;

/*we will temporary assume that the former number is the largest one*/
max=number1;

/*we check if the assumption was false*/ 
if(number2>max)
max=number2;

/*we print the result*/
cout<<”The larger number is”<<max<<endl;

/*we finish the program successfully*/
Return 0;
}

2.3.2

Image 1:

This is an image of a complete program to identify the largest of three numbers which is written out below in C++

/* finding the largest of three numbers */ 
#include<iostream>
using namespace std;

int main(void){
/*the three numbers*/
int,number1,number2,number3
/*we will save the larger number here*/ 
int max;
/*read three numbers*/
cin>>number1;
cin>>number2;
cin>>number3;
/*we will temporarily assume that the former number is the larger one*/
/*we will check it soon*/
max=number1;
/*we will check if the second value is the largest*/
if(number2>max)
max=number2;
/*we check if the third value is the largest*/
if(number3>max)
max=number3;
/*we print the result*/
cout<<”The largest number is “<<max<<endl;
/*we finish the program successfully*/
Return 0;
} 

2.3.3

Image 1:

This image shows various whole numbers and decimal numbers which have been written out below.

361,5242,5,3.14,6346 and 5. 

2.3.4

Image 1:

This is an image of pseudo-code which has been written out below.

1. max= -999999999;
2. read number
3. if(number == -1)print max next stop;
4. if(number > max)max = number
5. go to 2 

2.3.5

Image 1:

This is an image of a written statement which is written out below.

while my hands are dirty 
  i am washing my hands; 

2.3.6

Image 1:

This is an image of a while statement which has been written out below in C++.

while(conditional_expression)
    statement; 

2.3.7

Image 1:

This image shows a while statement with a block which is written out below in C++.

while(conditional_expression){
statement 1;
statement2;
statement3;
statement4; 
statement_n;
}

2.3.8

Image 1:

This is an image of a while statement which is stuck in a loop that cannot exit. This has been written out below in C++

while(1){
          cout<<”I am stuck inside a loop”<<endl;
}

2.3.9

Image 1:

This image shows how to declare a variable and assign a value at the same time in a C++ statement. This is written out below.

int variable = 0; 

2.3.10

Image 1:

This is an image of the declaration on the right side of the equal sign which is called an initiator. This enables us to use more complex C++ statements. These have been written out below.

 
float pi=3.1415;
double p12=2.0*pi; 

2.3.11

Image 1:

This is an image of a program with the while statements in a loop. These have been written out below.

#include<iostream>
using namespace std;
int main (void){ 
  /* temporary storage for the incoming numbers */
  int number;
  /* get the first value*/
  cin>>number
  /* we will store the currently greatest number here*/
  int max=number;
  /* if the number is not equal to -1 we will continue*/
  while(number != -1){
  /* is the number greater than max*/
  if(number > max)
  /* yes-update max*/
  max=number
  /*get next number*/
  cin>>number
}
   /*print the largest number*/
   Cout<<”The Largest Number is “<<max<<endl;
  /*finish the program successfully*/
  Return 0;
}

int main (void){ 
   /* we will count the numbers here */
   int Even=0, Odds=0;
   /* we will store the incoming numbers here */
   int Number;
   /* read the first number */ 
   cin>>Number
  /* 0 terminates execution */
   while(Number != 0){
   /* check if the number is odd */ 
   if(Number %2 == 1)
  /* increase the odd counter */ 
  Odds++;
  else 
          /* increase even counter */
         Evens++;
     /*read next number */ 
     cin>>Number;
} 
/* print Results */ 
cout<<” Even numbers: “<<Evens<<endl;
cout<<”odd numbers: “<<Odds<<endl;
return 0;
}

2.3.13

Image 1:

This image shows two while statements. These are written out below in C++

while(Number != 0) {...}
while(Number){....} 

2.3.14

Image 1: This is an image of an if statement which checks if a number is odd. This has been written out below in C++.

if(Number % 2==1)
if(Number % 2) 

2.3.15

Image 1:

This image shows a while statement which has been written out below in C++

int main (void){
int counter=5;
while(counter != 0){ 
    cout<<”I am an awesome program”<<endl;
    counter—
 } 
Return 0;
}

2.3.16

Image 1:

This image shows the while statement written in a program which has been compacted and is written out below in C++.

int main(void){
   int counter=5;
while(counter){
   cout<<”I am an awesome program”<<endl
   counter--;
   } 
   Return 0;
}

2.3.17

Image 1:

This image shows a while statement which is written out below in a simple program in C++.

int main(void){
    int counter=5;
    while(counter--)
        cout<<”I am an awesome program”<<endl;
        return 0;
}

2.3.18

Image 1:

This is an image of the do statement which is written out below in C++

do 
    statement
while(condition);
do{
     statement_1;
     statement_2;
     statement_3;
     statement_4;
     statement_n;
 }while(condition);

2.3.19

Image 1:

This image shows a program which has used a do loop statement instead of a while loop statement for searching for the largest number. This has been written out below.

#include<iostream>
using namespace std;

int main(void){
     int number;
     int max = -100000;
     int counter = 0;
     do{
              cin>>number
              if(number != -1)
                                counter++;
              if(number > max)
                                max = number;
           }while(number != -1);
           if(counter)
               cout<<”The largest number is  ”<<max<<endl;
           else
              cout<<”Are you kidding? You haven’t entered any number!“<<endl;
              return 0;
}

2.3.20

Image 1:

This is an image of a while statement which checks how many times the while loop has been executed. This has been written out below in C++.

 
int I;
i = 0;
while(i<100){
         /*the body goes here*/
         i++;
}

2.3.21

Image 1:

This image shows a generalised scheme for checking the amount of times a loop has been executed. Below is a concise way of writing the generalised scheme in C++.

initialization;
while(checking){
          /*the body goes here */
          modifying; 
}

2.3.22

Image 1:

This is an image of the for loop example which has been written out below.

for(initialization; checking; modifying){
/* The body goes here*/ 
} 

2.3.23

Image 1:

This is an image of another example of the for loop which is written out below in C++

for(i=0; i<100; i++){
     /*the body goes here*/
} 

2.3.24

Image 1:

This image shows another example of the for loop which is infinite; this is written out below.

for(;;){
   /*the body goes here*/
} 

2.3.25

Image 1:

This is an image of the for loop being used for a program for the first powers of 2. This has been written out below.

#include<iostream>
using namespace std;
int main (void){
int pow=1

for(int exp=0; exp<16; exp++){
        cout<<”2 to the power of”<<exp<<”is”<<pow<<endl;
        pow*=2 
        }
        return 0;
} 

2.3.26

Image 1:

This image shows the for loop with the break command. This is written out below.

#include<iostream>
Using namespace std;
int main(void){
int number;
int max = -100000
int counter = 0;
for(;;){
cin>>number;
if(number==-1)
     break;
counter++;
if(number>max)
       max=number;
}
if(counter)
     cout<<”The largest number is”<<max<<endl;
else
     cout<<”Are you kidding? You haven’t entered any number!”<<endl;
return 0;
} 

2.3.27

Image 1:

This image shows the for loop with the continue command which is written out below.

#include<iostream>
using namespace std;
int main(void){
int number; 
int max= -100000;
int counter = 0;
do{
        cin>>number
        if(number == -1)
                 continue;
              counter++;
              if(number > max)
                     max = number;
           }while(number != -1
           if(counter)
                 cout<<”The largest number is”<<max<<endl;
           else
                  cout<<”Are you kidding? You haven’t entered any numbers!”<<endl;
            return0;
           } 

2.3.19

Image 1:

This image shows a program which has used a do loop statement instead of a while loop statement for searching for the largest number. This has been written out below.

#include<iostream>
using namespace std;

int main(void){
     int number;
     int max = -100000;
     int counter = 0;
     do{
              cin>>number
              if(number != -1)
                                counter++;
              if(number > max)
                                max = number;
           }while(number != -1);
           if(counter)
               cout<<”The largest number is  ”<<max<<endl;
           else
              cout<<”Are you kidding? You haven’t entered any number!“<<endl;
              return 0;
}

2.3.20

Image 1:

This is an image of a while statement which checks how many times the while loop has been executed. This has been written out below in C++.

 
int I;
i = 0;
while(i<100){
         /*the body goes here*/
         i++;
}

2.3.21

Image 1:

This image shows a generalised scheme for checking the amount of times a loop has been executed. Below is a concise way of writing the generalised scheme in C++.

initialization;
while(checking){
          /*the body goes here */
          modifying; 
}

2.3.22

Image 1:

This is an image of the for loop example which has been written out below.

for(initialization; checking; modifying){
/* The body goes here*/ 
} 

2.3.23

Image 1:

This is an image of another example of the for loop which is written out below in C++

for(i=0; i<100; i++){
     /*the body goes here*/
} 

2.3.24

Image 1:

This image shows another example of the for loop which is infinite; this is written out below.

for(;;){
   /*the body goes here*/
} 

2.3.25

Image 1:

This is an image of the for loop being used for a program for the first powers of 2. This has been written out below.

#include<iostream>
using namespace std;
int main (void){
int pow=1

for(int exp=0; exp<16; exp++){
        cout<<”2 to the power of”<<exp<<”is”<<pow<<endl;
        pow*=2 
        }
        return 0;
} 

2.3.26

Image 1:

This image shows the for loop with the break command. This is written out below.

#include<iostream>
Using namespace std;
int main(void){
int number;
int max = -100000
int counter = 0;
for(;;){
cin>>number;
if(number==-1)
     break;
counter++;
if(number>max)
       max=number;
}
if(counter)
     cout<<”The largest number is”<<max<<endl;
else
     cout<<”Are you kidding? You haven’t entered any number!”<<endl;
return 0;
} 

2.3.27

Image 1:

This image shows the for loop with the continue command which is written out below.

#include<iostream>
using namespace std;
int main(void){
int number; 
int max= -100000;
int counter = 0;
do{
        cin>>number
        if(number == -1)
                 continue;
              counter++;
              if(number > max)
                     max = number;
           }while(number != -1
           if(counter)
                 cout<<”The largest number is”<<max<<endl;
           else
                  cout<<”Are you kidding? You haven’t entered any numbers!”<<endl;
            return0;
           } 

2.4.1

Image 1:

This image shows three words, these are: AND, OR, NOT.

2.4.2

Image 1:

This image shows a logical conjunction operator, in C++ this is the ampersand ampersand symbol which is written out below.

COUNTER > 0 && VALUE == 100

2.4.3

Image 1:

Below is an image of a logical conjunction operator ampersand truth table.

LeftRightLeft&&Right
falsefalsefalse
falsetruefalse
truefalsefalse
truetruetrue

2.4.4

Image 1:

Below is an image of a disjunction operator bar truth table.

LeftRightLeft| |Right
falsefalsefalse
falsetruetrue
truefalsetrue
truetruetrue

2.4.5

Image 1:

Below is an image of the truth table for the logical conjunction operator, which is an exclamation mark.

arg! arg
falsetrue
truefalse

2.4.6

Image 1:

This image shows some examples of logical conjunction expressions which have been written out below in C++.

Variable > 0  !(Variable <=0)
Variable != 0  !(Variable == 0) 

2.4.7

Image 1:

This is an image of De Morgan’s law which has been written out below in C++

!(p && q) == !p || !q
!(p || q) == !p && !q

2.4.8

Image 1:

This image shows an example of a logical operator argument which has been written out below in C++

BOOL i, j;
J = !!i;

2.4.9

Image 1:

Below are two images of the bitwise operator’s tables.

leftrightleft|rightleft&rightleft^right
00000
01101
10101
11110
arg~arg
01
10

2.4.10

Image 1:

This image shows the difference between logical and bit operators. This is written out below.

 
Logical operations: 
int i = 15, j = 22;

Bit operations: 
i: 00000000000000000000000000001111
j: 00000000000000000000000000010110

2.4.11

Image 1:

This image shows another example of the difference between logical and bit operators. This has been written out below.

Logical operations:
int log = i && j;

Bit operations: 
Log: 00000000000000000000000000000001 

2.4.12

Image 1:

This image shows an example of bitwise operation which is written out below.

int bit = i & j;
bit is equal to 6
bit = 0000000000000000000000000000110

2.4.13 Image 1:

This image shows examples of negation operations for logical and bitwise; these have been written out below.

Logical negations operations: 
int logneg = !i;

bitwise negation: 
int bitneg = ~i;

logneg:0000000000000000000000000000000
bitneg: 11111111111111111111111111110000

2.4.14

Image 1:

Below is an image of a table displaying examples of bitwise operations which show the difference between abbreviated and full C++ statements.

Full C++ statementAbbreviated C++
x= x & y;x & = y;
x= x | y;x |= y;
x= x ^ y;x ^= y;

2.4.15

Image 1:

This image shows a C++ variable declared in a special way. This is written out below.

int FlagRegister;

2.4.16

Image 1:

This is an image of the FlagRegister bit which has been written out below.

FlagRegister:000000000000000000000000000000x000

2.4.17

Image 1:

This image shows the bit mask program written out to detect the state of your bit. This has been written out below.

if(FlagRegister & TheMask){ 
    /*my bit is set*/ 
}else{
   /*my bit is reset*/
}

2.4.18

Image 1:

This image shows two examples of resetting the bit in C++ code; this has been written out below.

FlagRegister = FlagRegister & ~TheMask;
FlagRegister &= ~TheMask

2.4.19

Image 1:

This is an image of the bitwise disjunction operator being used to set your bit in the following two examples which have been written out below in C++.

FlagRegister = FlagRegister | TheMask;
FlagRegister |= TheMask;

2.4.20

Image 1:

This image shows the bitwise xor operation being used to negate your bit in the following examples which are written out below in C++

FlagRegister = FlagRegister ^ TheMask;
FlagRegister ^= TheMask; 

2.4.21

Image 1:

This image shows the bitwise shifting operation which is written out below.

Value << Bits 
Value >> Bits

2.4.22

Image 1:

This image is showing two C++ declarations as well as the shortened versions; these have been written out below.

Declarations: 
int Signed = -8, VarS;
unsigned Unsigned = 6, VarU;

shortened declarations:
/* equivalent to division by 2 -> VarS == -4 */
Vars = Signed >> 1;

/* equivalent to multiplication by 4 -> VarS == -32 */
VarS = Signed << 2;

/* equivalent to division by 4 -> VarU == 1 */
VarU = Unsigned >> 2;

/*  equivalent to multiplication by 2 -> VarU == 12 */
VarU = Unisgned << 1; 

2.4.23 Image 1:

This image shows the bitwise priority table. The table has two columns, column one displays the operators that have been used in the lesson so far and column two explains whether the operators are unary or binary. The table has been written out below.

! ~ (type) ++ -- + -unary
* / % 
+ -binary
<< >> 
< <= > >= 
== != 
& 
| 
&& 
|| 
= += -= *= /= %= &= ^= |= >>= <<= 

2.5.1

Image 1:

This is an image of an if statement cascade which is written out below in C++

if( i == 1)
     puts(“Only one?”);
else if(i == 2)
    puts(“i want more”);
else if(i == 3);
    puts(“not bad”);
else
   puts(“OK”)

2.5.2

Image 1:

This image shows the switch statement which is written out below.

switch(i){
case 1: puts(“Only one?”); break;
case 2: puts(“I want more”); break;
case 3: puts(“Not bad”); break;
case 4: puts(“OK”);
}

2.5.3

Image 1:

This image shows a switch statement which has been slightly modified and has been written out below.

switch(i){
case 1: puts(“Only one?”); break;
case 2: puts(“I want more”); break;
case 3:
case 4: puts(“OK”);
}

2.5.4

Image 1:

This image shows a switch statement with the default keyword, this is written out below.

switch(i){
case 1: puts(“Only one?”); break;
case 2: puts(“I want more”); break;
case 3:
case 4: puts(“OK”); break;
default: puts(“Don’t care”);
}

2.6.1

Image 1:

This image shows multiple variables declared in a statement, these have been written out below.

int var1, var2, var3, var4, var5, var6, var7, var8, var9;

2.6.2

Image 1:

This image shows an array statement which is written out below.

int numbers[5];
@}

!!!2.6.3 

Image 1: 

This image shows another array statement which has been written out below.

[@
Numbers[0] = 111;

2.6.4

Image 1:

This is another image of an array statement which is also written out below.

i = numbers[2];

2.6.5

Image 1:

This image also shows an array statement which is written out below.

numbers[1] = number[4];

2.6.6

Image 1:

This image shows an example of a number array to calculate the sum of all values. The example has been written out below.

int numbers[5], sum=0;
for(int i=0; i<5; i++)
       sum += numbers[i];

2.6.7

Image 1:

This image shows an example of a numbers array to calculate the sum of all values which are the same value. The example is written out below.

int numbers[5];
for(int i=0; i<5; i++)
    numbers[i]=2012

2.6.8

Image 1:

This image shows an array where the variables are in reverse order, the example has been written out below.

int variable1=1, variable2=2;
variable2= variable1;
variable1= variable2 

2.6.9

Image 1:

This image shows how to do an array in reverse order. This is how to do it.

 
int variable1 = 1, variable2 = 2, auxiliary;
auxiliary = variable1;
variable1 = variable2;
variable2 = auxiliary; 

2.6.10 Image 1:

This image shows two arrays where the variables are in reverse order. These have been written out below.

/* swap the elements #1 to #5 */
auxiliary = numbers[0];
numbers[0] = numbers[4];
numbers[4] = auxiliary;

/* swap elements #2 and #4 */
auxiliary = numbers[1];
numbers[1] = numbers[3];
numbers[3] = auxiliary

2.6.11

Image 1:

This image shows an array where the variables are in reverse order using the for loop. The array has been written out below.

for(int i = 0; i < 2; i++){
    auxiliary = numbers[i];
    numbers[i] = numbers[4 - i];
    numbers[4 - i] = auxiliary;
}

2.7.1

Image 1:

This image shows how to assign values to an array; this is known as array initialization. This has been written out below.

int vector[5] = {0,1,2,3,4};

2.7.2

Image 1:

This image shows values of an array where the values assigned are less than the array size. This has been written out below.

int vector[5] = {0,1,2};

2.7.3

Image 1:

This image shows values of an array where the values assigned are greater than the array size. This has been written out below.

int vector[5] = {0,1,2,3,4,5,6};

2.7.4

Image 1:

This image shows values of an array where the size of the array was not declared but an initiator was provided for the array size. This is written out below.

int vector[] = {0,1,2,3,4,5,6}

2.8.1

Image 1:

This image shows an array of any type with decimal numbers, this type of array is also known as a float. In this example the array can store 10 floating-point values. This has been written out below.

float FloatArr[10];   

2.8.2

Image 1:

This image shows an array that can store 20 characters. This example is written below.

char surname[20]; 

2.8.3

Image 1:

This is an image of an array with Boolean values, which are also called bool; this has been written out below.

bool votes[100];      

2.9.1

Image 1:

This image shows an array for a chess board, the declaration is written out below.

int row[8]; 

2.9.2

Image 1:

This image shows a two dimensional array for a chessboard; the declaration has been written out below.

int chessboard[8][8]; 

2.9.3

Image 1:

This image shows a table of a two dimensional array for a chessboard which has been written out below.

 ABCDEFGH 
1[0] [0][0] [1][0] [2][0] [3][0] [4][0] [4][0] [5][0] [6]1
2[1] [0][1] [1][1] [2][1] [3][1] [4][1] [5][1] [6][1] [7]2
3[2] [0][2] [1][2] [2][2] [3][2] [4][2] [5][2] [6][2] [7]3
4[3] [0][3] [1][3] [2][3] [3][3] [4][3] [5][3] [6][3] [7]4
5[4] [0][4] [1][4] [2][4] [3][4] [4][4] [5][4] [6][4] [7]5
6[5] [0][5] [1][5] [2][5] [3][5] [4][5] [5][5] [6][5] [7]6
7[6] [0][6] [1][6] [2][6] [3][6] [4][6] [5][6] [6][6] [7]7
8[7] [0][7] [1][7] [2][7] [3][7] [4][7] [5][7] [6][7] [7]8
 ABCDEFGH 

2.9.4

Image 1:

This is an image of code for a two dimensional array for the weather forecast which is written out below.

float temp [31][24];

2.9.5

Image 1:

This image shows code for a two dimensional array to find the highest temperature in a month for the weather, this has been written out below.

float temp [31][24];
float max = -100.0;

for(int day = 0; day < 31; day++)
  for(int hour = 0; hour < 24; hour++)   
    if(temp[day][hour] > max)
        max = temp[day][hour];
cout<<”The highest temperature was”<< max << endl; 

2.9.6

Image 1:

This is an image of code for a two dimensional array to count the number of days the afternoon temperature was at least 20 degrees centigrade. This has been written out below.

float temp[31][24];
int hotdays = 0;

for(int day = 0; day < 31; day++)
    if(temp[day][11] >= 20.0)
        hotdays++;
cout<<hotdays<<”days were hot”;

2.9.7

Image 1:

This image shows a two dimensional array on how to fill the entire array with zeroes for the coming month of the weather forecast. This has been written out below.

float temp[31][24];
int d, h;

for(d = 0; d < 31; d++)
  for(h = 0; h < 24; h++)
    temp[d][h] = 0.0;

2.9.8

Image 1:

This image shows a three dimensional array which is written out below.

int guests [3][15][20];

2.10.1

Image 1:

This image shows a string variable declaration, which has been written out below.

string student_name[100000];

2.10.2 (Image1): this image shows C++ statements on how many hours students have spent on the website studying; this has been written out below.

float student_time[100000];

2.10.3 Image 1:

This image shows an example of the structure command which has been written out below.

struct STUDENT {
   string name;
   float time;
   int  recent_chapter;
}

2.10.4 Image 1:

This is an image of the structure command and how to declare a variable for the structure command which is written out below.

struct STUDENT stdnt;
STUDENT stdnt2;

2.10.5

Image 1:

This image shows an example of a structure command with the selector operator; this has been written out below.

stdnt.time

2.10.6

Image 1:

This image shows a structure command being used in an array which has been written out below.

STUDENT STDNTS [100000];

2.10.7

Image 1:

This image shows how to declare the structure command which is written out below.

struct DATE { 
     int year;
     int month;
     int day;
};

2.10.8

Image 1:

This image shows the structure command inside another structure command. This is written out below.

struct STUDENT{
     string name;
     float time;
     int recent chapter;
     struct DATE last_visit;
} Harry Potter; 

2.11.1

Image 1:

This image shows the structure command field names overlapping with tag names in the code which is written out below.

struct STRUCT{
      int STRUCT;
}Structure;

Structure.STRUCT =0; /* STRUCT is a field name here */

2.11.2

Image 1:

This image is showing the structure command field names not overlapping with tag names in the code which has been written out below.

 
struct STR{
      int field;
}Structure;
int STR; 

Structure.field = 0;
STR = 1;

2.11.3

Image 1:

This image shows the structure command with two structures which have the same tag names or field names in the code; this has been written out below.

struct{
int f1;
} str1;

struct{
  char f1;
} str2;

str1.f1 = 32
str2.f1 = str1.f1

2.11.4

Image 1:

This image shows the initialization of the structure command which is written out below.

struct DATE date = {2012, 12, 21}; 

2.11.5

Image 1:

This is another image showing the initialization of the structure command which has also been written out below.

struct STUDENT he = {“Bond”, 3.5,4,{2012,12,21}};

2.11.6

Image 1:

This image shows the initialization of a structure command which is empty, this is written out below.

STUDENT nobody = { };
Edit - History - Print - Recent Changes - Search
Page last modified on August 01, 2017, at 12:02 PM