[CPP, C++] Arrays and Multi-Dimension Arrays, enum, constant variable


// ConsoleApplication3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;

//three global integers
int FirstNumber = 0 ;
int SecondNumber = 0 ;
int MultiplicationResult = 0 ;


void MultiplyNumbers ()
{
cout << "Enter the first number : " ;
cin >> FirstNumber ;

cout << "Enter the second number : " ;
cin >> SecondNumber;

MultiplicationResult = FirstNumber * SecondNumber ;

cout << "Displaying from MultiplyNumbers(): " ;
cout << FirstNumber << " x " << SecondNumber ;
cout << " = " << MultiplicationResult << endl;

}
enum RainbowColors
{
Violet = 0 ,
Indigo,
Blue,
Green,
Yellow,
Orange,
Red

};

enum CardinalDirections
{
North,
South,
East,
West
};


int _tmain(int argc, _TCHAR* argv[])
{
const double Pi = 22.0 / 7 ;
cout << " The value of constant Pi is: " << Pi << endl;

cout << "Displaying directions and their symbpolic values" << endl;
cout << "North:" << North << endl;
cout << "South:" << South << endl;
cout << "East:" << East << endl;
cout << "West:" << West << endl;

CardinalDirections WindDirection = South;
cout << "Variable WindDirection = " << WindDirection << endl;

int MyNumbers [4] = {1,8,5,3};

int YourNumbers[] = {1,5,45,88,2,33,58};

const int ARRAY_LENGTH = 5 ;

int MyNumber1s [ARRAY_LENGTH] = {0} ;

cout << "Enter index of the element to be changed: " ;
int nElementIndex = 0 ;
cin >> nElementIndex;

cout << " Enter new value: " ;
cin >> MyNumber1s [nElementIndex];

cout << "First element at index 0 : " << MyNumber1s [0] << endl;
cout << "Second element at index 1 : "<< MyNumber1s [1] << endl;
cout << "Thirht element at index 2 : " << MyNumber1s [2] << endl;
cout << "Fourth element at index 3 : " << MyNumber1s [3] << endl;
cout << "Fifth element at index 4 : " << MyNumber1s [4] << endl;


int SolarPanelIDs [2][3] = {{1,3,2}, {2,3,5}}; // First [] is row Second is column

cout << "Row 0 : " << SolarPanelIDs [0][0] <<  " " \
 << SolarPanelIDs[0][1] << " " \
<< SolarPanelIDs [0][2] << endl;

cout << "Row 1 : " << SolarPanelIDs[1][0] << " " \
  << SolarPanelIDs[1][1] << " " \
  << SolarPanelIDs[1][2] << endl;

return 0;
}

댓글

이 블로그의 인기 게시물

[C# Winform 예제] ScreenSaver 스크린세이버 만들기

아 정말 이사람 IELTS 관한 비법 글은.. 정말 공감10000%

Vocabulary for IELTS (2000 words) advanced level.