C++ tili qayta foydalaniluvchi dasturiy ta’minotni ishlab chiqish uchun shablon funksiyalar va sinflar bilan ta’minlaydi. Shablonlar funksiyalar va sinflarda turlarni muvofiqlashtirish (sozlash) qobiliyatini taqdim etadi



Download 45,76 Kb.
bet3/3
Sana09.12.2022
Hajmi45,76 Kb.
#882784
1   2   3
Bog'liq
5-Mustaqil ish

Massiv konteynerining SYNTAX:
array array_name;
Yuqoridagi kod, massiv_size ning maksimal hajmiga ega bo'lgan bo'sh ob'ekti qatorini yaratadi. Ammo, agar siz uning tarkibidagi elementlar qatorini yaratmoqchi bo'lsangiz, buni shunchaki = operatoridan foydalanib qilishingiz mumkin, bu erda bir misol:
#include
int main()
{
array odd_numbers = { 2, 4, 6, 8 };

}
u yuqoridagi bayonot 2,4,6,8 massivni ma'lumotlar qatori sifatida yaratadi. Shuni esda tutingki, {} qavslar bilan boshlash faqat c ++ da mumkin



Labaratoriya topshiriqlari(amaliy)
#include
#include
#include
using namespace std;
 
// Driver Code
int main()
{
multimap gquiz1; // empty multimap container
 
// insert elements in random order
gquiz1.insert(pair(1, 40));
gquiz1.insert(pair(2, 30));
gquiz1.insert(pair(3, 60));
gquiz1.insert(pair(6, 50));
gquiz1.insert(pair(6, 10));
 
// printing multimap gquiz1
multimap::iterator itr;
cout << "\nThe multimap gquiz1 is : \n";
cout << "\tKEY\tELEMENT\n";
for (itr = gquiz1.begin(); itr != gquiz1.end(); ++itr) {
cout << '\t' << itr->first << '\t' << itr->second
<< '\n';
}
cout << endl;
 
// adding elements randomly,
// to check the sorted keys property
gquiz1.insert(pair(4, 50));
gquiz1.insert(pair(5, 10));
 
// printing multimap gquiz1 again
 
cout << "\nThe multimap gquiz1 after adding extra "
"elements is : \n";
cout << "\tKEY\tELEMENT\n";
for (itr = gquiz1.begin(); itr != gquiz1.end(); ++itr) {
cout << '\t' << itr->first << '\t' << itr->second
<< '\n';
}
cout << endl;
 
// assigning the elements from gquiz1 to gquiz2
multimap gquiz2(gquiz1.begin(), gquiz1.end());
 
// print all elements of the multimap gquiz2
cout << "\nThe multimap gquiz2 after assign from "
"gquiz1 is : \n";
cout << "\tKEY\tELEMENT\n";
for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr) {
cout << '\t' << itr->first << '\t' << itr->second
<< '\n';
}
cout << endl;
 
// remove all elements up to
// key with value 3 in gquiz2
cout << "\ngquiz2 after removal of elements less than "
"key=3 : \n";
cout << "\tKEY\tELEMENT\n";
gquiz2.erase(gquiz2.begin(), gquiz2.find(3));
for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr) {
cout << '\t' << itr->first << '\t' << itr->second
<< '\n';
}
 
// remove all elements with key = 4
int num;
num = gquiz2.erase(4);
cout << "\ngquiz2.erase(4) : ";
cout << num << " removed \n";
cout << "\tKEY\tELEMENT\n";
for (itr = gquiz2.begin(); itr != gquiz2.end(); ++itr) {
cout << '\t' << itr->first << '\t' << itr->second
<< '\n';
}
 
cout << endl;
 
// lower bound and upper bound for multimap gquiz1 key =
// 5
cout << "gquiz1.lower_bound(5) : "
<< "\tKEY = ";
cout << gquiz1.lower_bound(5)->first << '\t';
cout << "\tELEMENT = " << gquiz1.lower_bound(5)->second
<< endl;
cout << "gquiz1.upper_bound(5) : "
<< "\tKEY = ";
cout << gquiz1.upper_bound(5)->first << '\t';
cout << "\tELEMENT = " << gquiz1.upper_bound(5)->second
<< endl;
 
return 0;
}
#include
#include
#include
#include
#include
#include
using namespace std;
int main()
{


string next;
string teams[10] = {"Clemson" , "Alabama" , "Georgia" , "Florida" , "Notre Dame" , "Auburn" , "Oklahoma" , "LSU" , "Miami FL" , "Oklahoma State"};
int select, ranking, teamoverall, wins, losses;
string team1, team2, userteam, nextgame;
int Alabama = 92;
int Clemson = 90;
int Georgia = 93;
int NotreDame = 88;
int MiamiFL = 80;
int Auburn = 86;
int Oklahoma = 85;
int LSU = 82;
int Florida = 90;
int OklahomaST = 78;
int Kansas = 60;
int Kentucky = 60;
int TexasAM = 65;
float score, oppscore;
int final, oppfinal, random, random1;


team1 = "Arkanasas";
team2 = "Oklahoma State";

wins = 0;
losses = 0;
cout << "COLLEGE FOOTBALL COACH - 2020" << endl;
cout << "1 - Manage" << endl;
cout << "2 - Manual" << endl;
cout << "3 - About" << endl;
cin >> select;
if(select == 1){
goto TeamSelect;
}
if(select ==2){
goto Manual;
}
if(select == 3){
goto About;
}

TeamSelect:
cout << string( 100, '\n' );
cout << "Choose a starting school to coach" << endl;
cout << "1- " << team1 << endl << "2- " << team2 << endl;
cin >> select;
if(select == 1){
userteam = "Arkansas";
ranking = 15;
nextgame = "Georgia";
teamoverall = 55;
}else{
userteam = "Oklahoma State";
ranking = 10;
nextgame = "Kansas";
teamoverall = 78;
}
goto Dynasty;


Dynasty:
cout << string( 100, '\n' );
cout << "Team - " << userteam << endl << endl;
cout << "Next Game - " << nextgame << " | Opponent Overall - ";
if(nextgame == "Georgia"){
cout << Georgia << endl << endl;
}else{
if(nextgame == "Kansas"){
cout << Kansas << endl << endl;
}else{
if(nextgame == "Kentucky"){
cout << Kentucky << endl << endl;
}else{
if(nextgame == "Auburn"){
cout << Auburn << endl << endl;
}else{
if(nextgame == "LSU"){
cout << LSU << endl << endl;
}else{
if(nextgame == "Texas A&M"){
cout << TexasAM << endl << endl;
}
}
}
}
}
}


cout << "Ranking - ";
if(ranking < 11){
cout << ranking << endl << endl;
}else{
cout << "UNRANKED" << endl << endl;
}
cout << "Record" << "(" << wins << " - " << losses << ")" << endl << endl;
cout << "Team Overall - " << teamoverall << endl << endl;
cout << "1- Play Next Game" << endl;
cout << "2- Recruting" << endl;
cout << "3- Rankings" << endl;
cin >> select;
if(select == 3){
goto rankings;
}else if(select ==1){
goto playgame;
}

playgame:
cout << string( 100, '\n' );
if(userteam == "Arkansas"){
if(nextgame == "Georgia"){
score = teamoverall * .5;
srand (time(NULL));
random = rand() % 5 + -20;
srand (time(NULL));
random1 = rand() % 20 + 1;
random = random + random1;

score = score + random;

oppscore = Georgia * .5;
srand (time(NULL));
random = rand() % 5 + -20;
srand (time(NULL));
random1 = rand() % 25 + 1;
random = random + random1;

oppscore = oppscore + random;

final = score;
oppfinal = oppscore;

if(final == oppfinal){
goto playgame;
}

if(final < 0){
final = 0;
}
if(oppfinal < 0){
oppfinal = 0;
}
if(final == 1){
final == 3;
}
if(final == 1){
final == 3;
}
if(oppfinal ==1){
oppfinal == 3;
}
if(score>oppscore){
wins = wins + 1;
teamoverall = teamoverall + 2;
}else{
losses = losses +1;
teamoverall = teamoverall - 2;
}

cout << "Arkansas scored " << final << " | Georgia scored " << oppfinal << endl << endl;
nextgame = "Kentucky";

cout << "Type 1 and press enter to continue..." << endl;
cin >> select;
goto Dynasty;

}else{
if(nextgame == "Kentucky"){
score = teamoverall * .5;
srand (time(NULL));
random = rand() % 5 + -20;
srand (time(NULL));
random1 = rand() % 20 + 1;
random = random + random1;

score = score + random;

oppscore = Kentucky * .5;
srand (time(NULL));
random = rand() % 10 + -25;
srand (time(NULL));
random1 = rand() % 25 + 1;
random = random + random1;

oppscore = oppscore + random;

final = score;
oppfinal = oppscore;

if(final == oppfinal){
goto playgame;
}


if(final < 0){
final = 0;
}
if(oppfinal < 0){
oppfinal = 0;
}
if(final == 1){
final == 3;
}
if(oppfinal ==1){
oppfinal ==3;
}

if(score>oppscore){
wins = wins + 1;
teamoverall = teamoverall + 2;
}else{
losses = losses +1;
teamoverall = teamoverall - 2;
}
cout << "Arkansas scored " << final << " | Kentucky scored " << oppfinal << endl << endl;
nextgame = "Auburn";
cout << "Type 1 and press enter to continue..." << endl;
cin >> select;
goto Dynasty;
}else{
if(nextgame == "Auburn"){
cout << string( 100, '\n' );
score = teamoverall * .5;
srand (time(NULL));
random = rand() % 5 + -25;
srand (time(NULL));
random1 = rand() % 20 + 1;
random = random + random1;

score = score + random;

oppscore = Auburn * .5;
srand (time(NULL));
random = rand() % 1 + -20;
srand (time(NULL));
random1 = rand() % 20 + 1;
random = random + random1;

oppscore = oppscore + random;

final = score;
oppfinal = oppscore;


if(final < 0){
final = 0;
}
if(oppfinal < 0){
oppfinal = 0;
}
if(final == 1){
final == 3;
}
if(oppfinal ==1){
oppfinal == 3;
}

if(final == oppfinal){
goto playgame;
}

if(score>oppscore){
wins = wins + 1;
teamoverall = teamoverall + 2;
}else{
losses = losses +1;
teamoverall = teamoverall - 2;
}

cout << "Arkansas scored " << final << " | Auburn scored " << oppfinal << endl << endl;
nextgame = "LSU";

cout << "Type 1 and press enter to continue..." << endl;
cin >> select;
goto Dynasty;
}else{
if(nextgame == "LSU"){
cout << string( 100, '\n' );
score = teamoverall * .5;
srand (time(NULL));
random = rand() % 5 + -15;
srand (time(NULL));
random1 = rand() % 25 + 1;
random = random + random1;

score = score + random;

oppscore = LSU * .5;
srand (time(NULL));
random = rand() % 1 + -20;
srand (time(NULL));
random1 = rand() % 25 + 1;
random = random + random1;

oppscore = oppscore + random;

final = score;
oppfinal = oppscore;


if(final < 0){
final = 0;
}
if(oppfinal < 0){
oppfinal = 0;
}
if(final == 1){
final == 3;
}
if(oppfinal ==1){
oppfinal ==3;
}

if(final == oppfinal){
goto playgame;
}

if(score>oppscore){
wins = wins + 1;
teamoverall = teamoverall + 2;
}else{
losses = losses +1;
teamoverall = teamoverall - 2;
}

cout << "Arkansas scored " << final << " | LSU scored " << oppfinal << endl << endl;
nextgame = "Texas A&M";

cout << "Type 1 and press enter to continue..." << endl;
cin >> select;
goto Dynasty;
}else{
if(nextgame == "Texas A&M"){
cout << string( 100, '\n' );
score = teamoverall * .5;
srand (time(NULL));
random = rand() % 10 + -20;
srand (time(NULL));
random1 = rand() % 30 + 1;
random = random + random1;

score = score + random;

oppscore = TexasAM * .5;
srand (time(NULL));
random = rand() % 5 + -15;
srand (time(NULL));
random1 = rand() % 20 + 1;
random = random + random1;

oppscore = oppscore + random;

final = score;
oppfinal = oppscore;


if(final < 0){
final = 0;
}
if(oppfinal < 0){
oppfinal = 0;
}
if(final == 1){
final == 3;
}
if(oppfinal ==1){
oppfinal = 3;
}

if(final == oppfinal){
goto playgame;
}

if(score>oppscore){
wins = wins + 1;
teamoverall = teamoverall + 2;
}else{
losses = losses +1;
teamoverall = teamoverall - 2;
}

cout << "Arkansas scored " << final << " | Texas A&M scored " << oppfinal << endl << endl;
nextgame = "Texas A&M";

cout << "Type 1 and press enter to continue..." << endl;
cin >> select;
goto Dynasty;
}
}
}
}
}
}








rankings:
cout << string( 100, '\n' );
cout << "1- " << teams[0] << endl;
cout << "2- " << teams[1] << endl;
cout << "3- " << teams[2] << endl;
cout << "4- " << teams[3] << endl;
cout << "5- " << teams[4] << endl;
cout << "6- " << teams[5] << endl;
cout << "7- " << teams[6] << endl;
cout << "8- " << teams[7] << endl;
cout << "9- " << teams[8] << endl;
cout << "10- " << teams[9] << endl;
cout << "Type 1 and press enter to go back..." << endl;
cin >> select;
goto Dynasty;
Manual:
cin >> select;
About:
cin >> select;

}

Download 45,76 Kb.

Do'stlaringiz bilan baham:
1   2   3




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©www.hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish