Please write in notepad or word document and send a screenshot through there. No
ID: 3721314 • Letter: P
Question
Please write in notepad or word document and send a screenshot through there.
Now for the code analysis, you need to explain what each line doe:s most important: what does the statement serve to the program . what sort of statement: e.g. declaration, assignment, expression, selection, repetition, etc what objects are used-e-Bnta double,string et what types are used: e.g. int, double, string e 10 #include "stdlibfacilities" 11 using namespace std 12 13 int main0 14 15 vector v; 16 int n; 17 int i-0 18 19 coutExplanation / Answer
#include <std_lib_facilities> // It is a header file which provides standard library facilities.
using namespace std; // A namespace is a declarative region that provides a scope to the identifiers (the names of types, functions, variables, etc) inside it.//
int main() // In C, C++ and few more programming languages, int main() is used as the entry point of the program.Here int denotes that the main() function will return an integer value to the system which is executing the main().//
{
vector <double> v; // Vectors are sequence containers which represent arrays which can change in size. Thus, we need not specify its length at the time of declaration and can change it later in the program. Here the type of vector is "Double".
int n; // It is a declaration statement where, if n is anything else, then int(n) will be called to convert it to an integer and the result will be assigned to n .
int i=0; // In this statement i is declared to be an integer and the value assigned to it os "0".
cout<<an"Enter 5 numbers: "; // On most program environments, the standard output by default is the screen, and the C++ stream object defined to access it is cout . For formatted output operations, cout is used together with the insertion operator, which is written as <<. defines after insertion of input in the screen i.e five numbers jump to "Next line".
cout<<"Press ctrl-z or ctrl-d to finish "; // Cout displays the output on the screen. Here it request to press either ctrl z or ctrl d.
while(i<5) // The condition inside the while (i <5) will be executed 5 times before it becomes false. Once that happens, the code inside the while block won't be executed anymore and the rest of the code will keep running until the end of the file.
{
cin >> n; // cin is the standard input stream. Usually the stuff someone types in with a keyboard. We can extract values of this stream, using the >> operator. So cin >> n; reads an integer. Here it reads the value of n.
v.push_back(n); // A standard vector can be expanded to hold one more member i.e expansion of the vector by adding more items.
i++; // i++ is an increment operator which means i=i+1.
}
int min=v[0]; // It is a declaration statement where min is declared as integer type and the value is equals to the value of v[0].
for(int i=0;i<v.size();i++) // It is a loop which states that if i=o and i less than the vector size v, then go to the next line. After execution of the entire loop return back where i will be equal to i+1. Continue the loop till the statement become false and after that come outside the loop to execute next statement.
{
if(min>v[i]) // If is a conditional clause. Here it checks wheather the value of min is greater than v[i] or not. if yes go to next statement.
{
min=v[i]; // Here the statement assigns the value of v[i] to min.
}
}
cout<<"Min::"<< min<< endl; // This statement shows the value of min and endl statement is used to close the statement.
return 0; // The return value of the main function is considered the "Exit Status" of the application. On most operating systems returning 0 is a success status
}