Which represents the exam scores
of the students with the corresponding ids:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Search(
const ItemType list[],
ItemType item,
int length,
int& index,
bool& found )
{
for (index = 0;
index < length &&
list[index] != item;
index++);
found = index < length);
}
cout << "Enter
id: ";
cin >> student;
Search(id, student,
5, location, found);
if (found)
cout <<
"Grade for student"
<< student << " is "
<< exam[location] << endl;
else
cout <<
"Student " << student
<< " was not found." << endl;
}
found = index < length;
}
Are there any additional requirements for list in order
for the function to work properly?
for (pass = 0;
pass < length - 1;
pass++)
{
minIndex
= pass;
//
find next smallest item
for (place
= pass + 1;
place < length;
place++)
{
if (list[place] < list[minIndex])
minIndex = place;
}
//swap
items
temp = list[minIndex];
list[minIndex]
= list[pass];
list[pass]
= temp;
}
}
SearchOrd(list, item,
length,
index, found);
// move items down
for (count = length
- 1;
count >= index;
count--)
list[count
+ 1] = list[count];
// insert item
list[index]
= item;
// increment length of
list
length++;
}
found = false;
while (!found &&
last >= first)
{
middle =
(first + last) / 2;
if (item
< list[middle])
last = middle - 1;
else if
(item > list[middle])
first = middle + 1;
else
found = true;
}
index = middle;
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char promptMsg[] = "Enter a positive
number: ";
char errMsg[] = "Value must be
positive.";
promptMsg is stored in 26
locations, one for each character plus one for the null character.
char promptMsg[] = "Enter a name: ";
char name[30];
cout << promptMsg;
cin >> name;
char oneLine[81];
cin.get(oneLine, 81);
reads up to 81 characters or until the end of the line
('\n' character).
char oneLine[81];
char dummy;
cin.get(oneLine, 81);
cin.get(dummy); // consume the
end of line
char response[5];
cin.get(response, 5);
cin.ignore(100, '\n');
This will skip up to 100 characters or until the end of
line character is encountered.
ifstream inFile;
char fileName[51];
cout << "Enter file name: ");
cin.get(fileName, 51);
cin.ignore(100, '\n');
inFile.open(fileName);
if(!inFile)
{
cout << "Unable to
open file "
<< fileName << endl;
return 1;
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|