Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ help.. Can not seem to get these codes to run on myprogramming lab. Seriousl

ID: 3670221 • Letter: C

Question

C++ help..

Can not seem to get these codes to run on myprogramming lab. Seriously need some help.

Project 14: Prime Numbers. Write a program that reads in an integer that is greater than 2 (let's call it k) and finds and prints all of the prime numbers between 3 and k. A prime number is a number such that 1 and itself are the only numbers that evenly divide it (for example, 3, 5, 7, 11, 13, 17, ...).

One way to solve this problem is to use a doubly nested loop. The outer loop can iterate from 3 to k while the inner loop checks to see if the counter value for the outer loop is prime. One way to see if number n is prime is to loop from 2 to n-1 and if any of these numbers evenly divides n, then n cannot be prime. If none of the values from 2 to n-1 evenly divides !n, then n must be prime. (Note that there are several easy ways to make this algorithm more efficient.)

SAMPLE RUN: Enter n (to print primes from 3 to n):12
3 is a prime number.
5 is a prime number.
7 is a prime number.
11 is a prime number.

Project 15: Buoyancy. Buoyancy is the ability of an object to float. Archimedes’ principle states that the buoyant force is equal to the weight of the fluid that is displaced by the submerged object . The buoyant force can be computed by


Fb = V × y

where Fb is the buoyant force, V is the volume of the submerged object , and y is the specific weight of the fluid. If Fb is greater than or equal to the weight of the object , then it will float, otherwise it will sink.

Write a program that inputs the weight (in pounds) and radius (in feet) of a sphere and outputs whether the sphere will sink or float in water. Use y = 62.4 lb/cubic feet as the specific weight of water. The volume of a sphere is computed by (4/3)(r cubed).

SAMPLE RUN: Enter the radius of the sphere, in feet:2
Enter the weight of the sphere, in pounds:2000
The sphere will float.

Project 18: Broken Keypad. The keypad on your oven is used to enter the desired baking temperature and is arranged like the digits on a phone:


123

456

789

0

Unfortunately the circuitry is damaged and the digits in the leftmost
column no longer function. In other words, the digits 1, 4, and 7 do not work. If a recipe calls for a temperature that can’t be entered, then you would like to substitute a temperature that can be entered. Write a program that inputs a desired temperature. The temperature must be between 0 and 999 degrees. If the desired temperature does not contain 1, 4, or 7, then output the desired temperature. Otherwise, compute the next largest and the next smallest temperature that does not contain 1, 4, or 7 and output both.
For example, if the desired temperature is 450, then the program should output 399 and 500. Similarly, if the desired temperature is 375, then the program should output 380 and 369.

SAMPLE RUN:

Enter the desired temperature:642, 639, 650

Explanation / Answer

1. PRIME CHECK
----------------------------
#include <iostream>
using namespace std;
// prime number is not divisible by any number except 1 and itself
// also its effiecient to not check with number after number/2.

int main()
{
int number, i, numToCheck, flag=0;
cout << "Enter a positive integer: ";
cin >> number;
for(numToCheck = 3; numToCheck <= number; numToCheck++){
for(i = 2, flag = 0; i <= numToCheck/2; ++i){
if(numToCheck % i == 0) {
flag=1;
break;
}
}
if (flag==0){
cout << numToCheck << " is a prime number ";
}
}
return 0;
}

2. buoyancy force
---------------------------------
#include <iostream>
#include <math.h>
using namespace std;

int main ()
{
float y = 62.4;//Constant given, float value
float weight;
float radius;
double volume;
double buoyantForce;
double PI = M_PI;
cout<< "Please enter radius of the object in feet : " << endl;
cin >> radius ;
  
cout<< "Please enter weight of the object in pound : " << endl;
cin>> weight;
  
volume = ((4 * PI * (radius * radius * radius))/ 3); //Calculates Volume
buoyantForce = (volume)*(y); //Calculates Buoyant Force
  
// cout << "volume - " << volume << " PI-" << M_PI << " buoyantForce - " << buoyantForce << endl;
  
if (buoyantForce >= weight) { // Checks whether buoyantForce is greater than or equal to weight of sphere
cout << "This Sphere will float!" << endl;
} else { //If buoyantForce is less than weight
cout << "This Sphere will sink!" << endl;
}
  
return 0;
}
3. Broken Key pad
---------------------------
#include <iostream>
using namespace std;

int main()
{
int temperature, hundreds, tenth, ones, minimum, maximum;
cout << "Enter a positive integer in bet (0 - 999): ";
cin >> temperature;
if( temperature >= 1000 || temperature < 0 ){
cout << "please enter valid temperature ";
return 0;
}
hundreds = temperature / 100;
//cout<<" hundreds" << hundreds;
if(hundreds == 1 || hundreds == 4 || hundreds == 7){
minimum = (hundreds-1) * 100 + 99;
maximum = (hundreds+1) * 100;
cout << minimum << " && " << maximum << " ";
return 0;
}
tenth = (temperature / 10) % 10;
//cout << " tenth" << tenth;
if(tenth == 1 || tenth == 4 || tenth == 7){
minimum = hundreds * 100 + (tenth-1) * 10 + 9;
maximum = hundreds * 100 + (tenth+1) * 10;
cout << minimum << " && " << maximum << " ";
return 0;
}
% 10;
//cout << " ones - " << ones;
if(ones == 1 || 4 || 7){
minimum = hundreds * 100 + tenth * 10 + ones-1;
maximum = hundreds * 100 + tenth * 10;
cout << minimum << " && " << maximum << " ";
return 0;
}
cout << temperature << " ";
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote