Код: Выделить всё
// GameOver
// Первая программа на С++
#include <iostream>
int main()
{
std::cout << "Game Over ! " <<std::endl ;
return 0;
}
Код: Выделить всё
// GameOver
// Первая программа на С++
#include <iostream>
int main()
{
std::cout << "Game Over ! " <<std::endl ;
return 0;
}
Код: Выделить всё
// Программа Game Over 2.0
// Демонстрирует работу с директивой using
#include <iostream>
using namespace std;
int main()
{
cout << "Game Over ! " << endl ;
return 0;
}
Код: Выделить всё
// Программа Game Over 3.0
// Демонстрирует работу с объявлениями using
#include <iostream>
using std::cout;
using std::endl;
int main()
{
cout << "Game Over!" << endl;
return 0;
}
Код: Выделить всё
// Дорогой калькулятор
// Демонстрирует работу со встроенными арифметическими операторами
#include <iostream>
using namespace std;
int main()
{
cout << "7 + 3 = " << 7 + 3 << endl;
cout << "7 - 3 = " << 7 - 3 << endl ;
cout << "7 * 3 = " << 7 * 3 << endl ;
cout << "Делимое и делитель целое, поэтому делится без остатка: 7 / 3 = " << 7 / 3 << endl ;
cout << "7.0 / 3.0 = " << 7.0 / 3.0 << endl;
cout << "7 % 3 = " << 7 % 3 << endl ;
cout << "7 + 3 * 5 = " << 7 + 3 * 5 << endl ;
cout << " (7 + 3) * 5 = " << (7 + 3 ) * 5 << endl ;
return 0;
}
Код: Выделить всё
#include <stdio.h>
#include <windows.h>
int main() {
int c, n;
UINT oldCodePage;
char buf[1024];
oldCodePage = GetConsoleOutputCP();
if (!SetConsoleOutputCP(65001)) {
printf("error\n");
}
freopen("uc-test-UTF-8-nobom.txt", "rb", stdin);
n = fread(buf, sizeof(buf[0]), sizeof(buf), stdin);
fwrite(buf, sizeof(buf[0]), n, stdout);
SetConsoleOutputCP(oldCodePage);
return 0;
}
Код: Выделить всё
// Программа Game Stats
// Демонстрирует объявление и инициализацию переменных
#include <iostream>
//Объявление и инициализация переменных
using namespace std;
int main()
{
int score;
double distance;
char playAgain;
bool shieldsUp;
short lives, aliensKilled;
score = 0;
distance = 1200.76;
playAgain = 'y';
shieldsUp = true;
lives = 3;
aliensKilled = 10;
double engineTemp = 6572.89;
cout << "\nscore; " << score << endl;
cout << "distance; " << distance << endl;
cout << "playAgain; " << playAgain << endl;
// пропускаем shieldsUp, поскольку булевы значения.
// как правило. на экран не выводятся
cout << "lives; " << lives << endl;
cout << "aliensKilled; "<< aliensKilled << endl;
cout << "engineTemp; "<< engineTemp << endl;
int fuel ;
cout << "\nHow much fuel? ";
cin >> fuel;
cout << "fuel; " << fuel << endl;
typedef unsigned short int ushort;
ushort bonus = 10;
cout << "\nbonus; " << bonus << endl;
return 0;
}
Код: Выделить всё
// Программа Game Stats 3.0
// Демонстрирует работу с константами
#include <iostream>
using namespace std;
int main()
{
const int ALIEN_POINTS = 150;
int aliensKilled = 10;
int score = aliensKilled * ALIEN_POINTS;
cout << "score: " << score << endl ;
enum difficulty {NOVICE, EASY, NORMAL, HARD, UNBEATABLE};
difficulty myDifficulty = EASY;
enum shipCost {FIGHTER_COST = 25, BOMBER_COST, CRUISER_COST = 50};
shipCost myShipCost = BOMBER_COST;
cout << "\nTo upgrade my ship to a Cruiser will cost "
<< (CRUISER_COST - myShipCost) <<" Resource Points.\n";
return 0;
}
Код: Выделить всё
11 Утраченный клад
11 Персонализированная приключенческая игра
#include <iostream>
#include <string>
using std: :cout:
using std: :cin:
using std: :endl:
usingstd: :string:
Код: Выделить всё
int main()
{
const int GOLD_PIECES = 900:
int adventurers. killed. survivors:
st ri ng 1 eader:
11 получаю информацию
cout « "Welcome to Lost Fortune\n\n":
cout « "Please enter the following for your personalized adventure\n":
cout « "Enter а number: "
cin >> adventurers:
cout « "Enter а number. sma 11 er than the fi rst: "
cin » killed:
survivors = adventurers - killed:
cout « "Enter your 1 ast name: " :
cin»leader:
11 сюжет
cout « "\nA brave group of" « adventurers « " set out on а quest ":
cout « "-- in search of the lost treasure of the Ancient Dwarves. ":
cout « "The group was led Ьу that legendary rogue. " « leader « ". \n":
cout « "\nAl ong the way. а band of maraudi ng ogres ambushed the party. "
cout « "All fought bravely under the command of " « leader:
cout « ". and the ogres were defeated. but at а cost. ":
cout « "Of the adventurers. " « ki 11 ed « " were vanqui shed. "
cout « "leaving just "« survivors «" in the group.\n":
cout « "\nThe party was about to give up all hope. "
cout « "But while laying the deceased to rest. ":
cout « "they stumbled upon the buried fortune. ":
cout « "So the adventurers split "« GOLD_PIECES «" gold pieces.":
cout « leader «" held on to the extra "« (GOLD_PIECES % survivors):
cout «" pieces to keep things fair of course.\n":
return 0;
}