how to write pseudo code for c++?? --------- #include <iostream> #include <fstre
ID: 3829238 • Letter: H
Question
how to write pseudo code for c++??
---------
#include <iostream>
#include <fstream>
using namespace std;
int searchList(int stdList[], int numElems, int value)
{
int i, loc = -1;
for (i = 0; i<numElems; i++)
{
if (stdList[i] == value)
{
loc = i;
break;
}
}
return loc;
}
int main()
{
int arrStd[100], countStd = 0;
int arrTest[50], countTest = 0;
int i;
ifstream infile;
infile.open("LSStandard.txt");
if (!infile)
{
cout << " Standerd File does not exist";
}
else
{
while (!infile.eof())
{
infile >> arrStd[countStd];
countStd++;
}
}
infile.close();
ifstream infile2;
infile2.open("LSTest.txt");
if (!infile2)
{
cout << " Test File does not exist";
}
else
{
while (!infile2.eof())
{
infile2 >> arrTest[countTest];
countTest++;
}
}
infile2.close();
cout << endl;
for (i = 0; i<countTest; i++)
{
int loc = searchList(arrStd, countStd, arrTest[i]);
if (loc == -1)
cout << " Number " << i + 1 << " (" << arrTest[i] << ") was not in file.";
else
cout << " Number " << i + 1 << " (" << arrTest[i] << ") was located at index " << loc;
}
cout << endl;
system("Pause");
return 0;
}
//OUTPUT
Number 1 (79) was located at index 44 Number 2 (17) was located at index 18 Number 3 (11) was located at index 5 Number 4 (102 was not in file. Number 5 (41) was not in file Number 6 (26) was not in file Number 7 (43) was located at index 0 Number 8 (30) was located at index 41 Number 9 (55) was located at index 33 Number 10 (39) was located at index g Number 11 (43) was located at index 0 Number 12 (48) was not in file Number 13 (11) was located at index 5 (42) was not Number 1 Number 15 (10) was not in file Number 16 (103) was located at index 20 Number 17 (43) was located at index 0 Number 18 (55) was located at index 33 Number 19 (88) was located at index 34 Number 20 (77) was located at index 16 Number 21 (33) was not in file. Number 22 (23) was not in fileExplanation / Answer
declare arrStd[100] of type integer array
declare arrTest[100] of type integer array
declare and initializr countStd, countTest to 0
Open file "LSStandard.txt"
If file cannot be open
print "Standerd File does not exist"
stop execution
end if
while EndOfFile not reached
read integer from file and store in arrStd[countStd]
increment countStd by 1
end while
close file LSStandard.txt
Open file "LSTest.txt"
If file cannot be open
print "Test File does not exist"
stop execution
end if
while EndOfFile not reached
read integer from file and store in arrTst[countTst]
increment countTst by 1
end while
close file LSTest.txt
for each element of arrTest[]
found = search arrTest[i] in arrStd[]
if (found)
print "found at location"
print found.location
else
print "not found"
end if
end for
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.