13)
The output is 7(::p) + 90 (p) - 5.5(var) = 91.5
14)
7 times
from 0-9 there are 10 numbers out of which # will not be printed for 2,4,6 hence # will be printed for 10-3 = 7 numbers.
15)
a. double pow(double x,double y)
The pow() function takes ‘double’ as the arguments and returns a ‘double’ value.
b. T floor(T x) where T can be double,float,long double.
The floor() function takes a single argument and returns a value of type double, float or long double type.
16)
a. False, isupper retruns an int value
b. False, for loop is pre-test loop(test expression is evaluated before running the body of the loop) whereas do-while loop is a post-test loop(test expression is evaluated after executing the body of the loop)
c. False
Consider the following:
if(var < 100)
{
if(var <50)
{
cout << "Less than 50" << endl;
}
}
else
{
cout << "Greater than 100" << endl;
}
In this else is paird with if(var < 100) and not with if(var < 50).
d. True, bool stores either true or false.
e. True
program. 13. What's the output of the following program? #include< iostream> #include&math> using namespace std; int...
Need a FLOW Chart for that code.
#include <iostream > using namespace std; int PowerFive(int); //Function prototype declaration int main() for (int i=-10 ; i(z10; 1++) {//for each # cout<<"("<< ǐ<<") ^5. "<<PowerFive(1)くくendl;// calling the defined Function int PowerFive (int a) //Function definition return a*a*a*a*a;
#include <iostream> #include <cmath> #include <iomanip> #include <cstdlib> using namespace std; bool isInt (double value) { double dummy; return bool(modf(value, &dummy) == 0); } double sqr(double value) { return value * value; } double calcFrictionFactor(double R, double D, double epsilon) { const double BlasiusCoefficient = 0.3164; double f_old, f_new; f_new = BlasiusCoefficient * pow(R, -0.25); // loop until our two values are within 0.000001 of each other do { f_old = f_new; // previous guess is now the old one...
#include <fstream> #include <iostream> #include <cstdlib> using namespace std; // Place charcnt prototype (declaration) here int charcnt(string filename, char ch); int main() { string filename; char ch; int chant = 0; cout << "Enter the name of the input file: "; cin >> filename; cout << endl; cout << "Enter a character: "; cin.ignore(); // ignores newline left in stream after previous input statement cin.get(ch); cout << endl; chcnt = charcnt(filename, ch); cout << "# of " «< ch« "'S:...
Program 2 #include <iostream> #include <cmath> using namespace std; int main() { const double PI = 3.141592653; int degrees; double radians; cout << "Enter a value for the degree of an angle\n"; cin >> degrees; // translate the formula for converting degrees to radians into C++: // // degrees x PI // ------------ = radians // 180 radians = _____________________________________; // Refer to p. 127 for help below....
#include "stdafx.h" #include <iostream> using namespace std; class dateType { private: int dmonth; int dday; int dyear; public: void setdate (int month, int day, int year); int getday()const; int getmonth()const; int getyear()const; int printdate()const; bool isleapyear(int year); dateType (int month=0, int day=0, int year=0); }; void dateType::setdate(int month, int day, int year) { int numofdays; if (year<=2008) { dyear=year;...
Give the output of the following C++ program and explain your reasoning: #include <iostream> using namespace std; int gcd( int , int ); //Function prototype int main() { int a = 105; int b = 30; cout << “The GCD of “ << a << “ and “ << b << “ is “ << gcd(a,b) << endl; return 0; } int gcd(int a, int b) { if ( b == 0 ) return a; else return gcd(b,a%b); }
#include <iostream>
#include <queue>
using namespace std;
class Graph {
public:
Graph(int n);
~Graph();
void addEdge(int src, int tar);
void BFTraversal();
void DFTraversal();
void printVertices();
void printEdges();
private:
int vertexCount;
int edgeCount;
bool** adjMat;
void BFS(int n, bool marked[]);
void DFS(int n, bool marked[]);
};
Graph::Graph(int n=0) {
vertexCount = n;
edgeCount = 0;
if(n == 0)
adjMat = 0;
else {
adjMat = new bool* [n];
for(int i=0; i < n; i++)
adjMat[i] = new bool [n];
for(int i=0;...
Watermelon Problem: The answer should not include any whitespace. #include<iostream> using namespace std; int main() { double distance, gravity =9.8, height; int time, t=0; cout<<"Please input the time of fall in seconds:"<<endl; [ A ] // Get the user input of the time of fall in seconds (Use cin>> method) cout<<endl; cout<<"Please input the height of the bridge in meters:"<<endl; [ B ] // Get the user input of the height of the bridge in meters (Use cin>>...
Fix this code so only the function prototype comes before main. #include <iostream> using namespace std; bool isMultiple(int num1, int num2) { return num1 % num2 == 0; } int main() { char ch = 'Y'; int num1, num2; while(ch =='Y') // While ch is equal to Y { cout << "Enter two numbers(largest first): "; cin >> num1; // Getting 1st number cin >> num2; // Getting 2nd number if(isMultiple(num1, num2)) cout << num2 << " " << "IS...
Find and fix errors #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int MIN = 1; const int MAX = 10; int getRandom(int low, int high); int main() { int random_num = 0; int player_num; int tries; int seed = static_cast<int>(time(0)); bool guessed = false; srand(seed); // call the getRandom function below tries = 4; while ( tries > 0 && !guessed ) { cout << "Enter a number within the range 1 to...