:
السلام عليكم اريد المساعده ضروري
في هذا البرنامج .. بكره عندي فاينل ومافهمت هذا السؤال كيف استدعي داله ..؟؟! والله ما اعرف تعبت وانا احاول افهم وماقدر تكفون افيدوني
:huh: :huh: :huh:
Write a program that reads 3 strings from the user and store them in an array. Then call a method that prints the contents of that array. After that, your program prompts the user to enter a string to search for it by calling a method search. This method searches for the given string and if it is found prints “FOUND!!” and returns its index, otherwise prints “NOT FOUND!!” and return -1.
Sample run: Enter 3 strings: String#1: Nora String#2: Huda String#3: Sara The array contents are: Nora Huda Sara Please, enter a string to search for it: Nora FOUND!!
هذا الكود حقه
#include <iostream>
#include <string>
using namespace std;
void print(string a[] , int size);
int search(string a[] , string str , int size);
int main()
{
string arrayS[3] , searchStr;
int i;
cout<< "Enter 3 strings:\n" ;
for ( i=1 ; i<=3 ; i++)
{cout << "String#" << i << ": " ; cin >> arrayS[i-1] ;}
print(arrayS , 3);
cout << "Please, enter a string to search for it: " ; cin>>searchStr;
search(arrayS , searchStr , 3);
}
void print(string a[] , int size)
{
for(int i=0 ; i< size ; i++)
cout << a << endl;
}
int search(string a[] , string str , int size)
{
int foundIndex =-1;
for(int i=0 ; i < size ; i++)
if (a.compare(str) == 0)
{foundIndex = i;
cout << "FOUND!!\n";
}
if (foundIndex == -1)
cout << "NOT FOUND!!\n";
return foundIndex;
}