ContainsWord nomli mantiqiy funksiya yaratish


Download 16.5 Kb.
Sana30.11.2019
Hajmi16.5 Kb.

/*

Mahsulot nomlaridan tashkil topgan ro’yhat berilgan. Ro’yhat elementlaridagi SONY firmasida ishlab chiqilgan mahsulotlardan tashkil topgan yangi ro’yhat yarating.

Algoritmi:

ContainsWord nomli mantiqiy funksiya yaratish;

Undan faqat true yoki false qiymat qaytaradi.

Royhat yaratish;

Royhatga malumot kiritish;

Sony sozini malumotda qatnashganligini tekshirish;

Sony sozi qatnashgan malumotlarni chiqarish.

*/

Dasturiy korinishi:



#include "iostream"

#include "string"

#include "list"

using namespace std;

bool containsWord(string word, string inLine) {

int wlen, counter = 0, slength = inLine.length() - word.length() + 1;

wlen = word.length();

for(int i = 0; i < slength; i++) {

for(int j = 0; j < word.length(); j++){

if(word[j] == inLine[i + j])

counter++;

else{


counter = 0;

break;


}

}

if(counter == wlen) {



return true;

}

counter = 0;



}

return false;

}

main()


{

list brands;

brands.push_front("Televizor-Artel");

brands.push_front("Changyutgich-Roison");

brands.push_front("Telefon-Sony");

brands.push_front("Notebook-Asus");

brands.push_front("Konditsioner-Sony");

brands.push_front("Playstation-Sony");

brands.push_front("Muzlatgich-Artel");

brands.push_front("Blender-Artel");

brands.push_front("Televizor-Sony");

brands.push_front("Notebook-Acer");

string current, brand = "Sony";

list sonyBrands, bCopy = brands;

for(int i = 0; i < brands.size(); i++) {

current = bCopy.front();

if(containsWord(brand, current)) {

sonyBrands.push_front(bCopy.front());

}

bCopy.pop_front();



}

list copy = sonyBrands;

cout << endl << "Sony brendi ostidagi tovarlar:" << endl << endl;

for(int i = 0; i < sonyBrands.size(); i++) {

cout << copy.front() << endl;

copy.pop_front();



}
Download 16.5 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2020
ma'muriyatiga murojaat qiling