Ans 3:
#include <iostream>
using namespace std;
int main() {
// Variables to hold operands
float f1, f2;
// Variable to hold operator
char op;
// Requesting user to input operands
cout << "\nEnter a number: ";
cin >> f1;
cout << "Enter another number: ";
cin >> f2;
// Requesting user to input operator
cout << "\nEnter a operator: ";
cin >> op;
cout << "\n";
switch(op)
{
case '+':
cout << f1 << " + " << f2 << "
= " << f1 + f2;
break;
case '-':
cout << f1 << " - " << f2 << "
= " << f1 - f2;
break;
case '/':
cout << f1 << " / " << f2 << "
= " << f1 / f2;
break;
case '*':
cout << f1 << " * " << f2 << "
= " << f1 * f2;
break;
default:
cout << "Invalid Operator!";
}
return 0;
}
/*********** Output ****************/
Ans 4:
#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;
int main()
{
srand(time(0));
cout << "\nRandom No generated (0.. 100): " << rand() %
101;
return 0;
}
/*************** below is the output *******************/
/********* Note: if you are using -std=c++11 (c++ 11) then you don't need to include stdlib.h *************/
/********** I have included stdlib.h, to just show how it will work in other versions of c++ ***********/
/************ srand(time(0)) seeds the random number generator with current system time, if you don't do this, everytime the code runs you will get the same random number ****************/
/*********** if you have any questions, you may ask in comments *****************/
/**************** thanks for reading ******************/
5. Numerical Integration (15 marks] When a charged particle moves perpendicular to a magnetic field it...