Questions
Decision Structures Calorie Calculator Assignment Overview This assignment will give you practice with numerical calculations, simple...

Decision Structures Calorie Calculator Assignment Overview This assignment will give you practice with numerical calculations, simple input/output, and if-else statements. Program Objective: In this exercise, you will write a program the calculates the Daily Caloric needs for weight lose diet. According to everydayhealth.com they recommend this daily caloric formula for a weight loss diet: BMR + Activity Level - 500 calories. Calories Calculator The Harris-Benedict equation estimates the number of calories your body needs to maintain your weight if you do no exercise. This is called your basal metabolic rate or BMR. The Calories needed for a woman to maintain her weight is: BMR = 655 + (4.3 * weight in pounds) + (4.7 * height in inches) - (4.7 * age in years) The Calories needed for a man to maintain his weight is: BMR = 66 + (6.3 * weight in pounds) + (12.9 * height in inches) - (6.8 * age in years) Next, the total daily caloric requirement is calculated by multiplying your BMR by your level of activity: • If the person is inactive (rarely exercise), then increase the calculated BMR 20%. • If the person is somewhat active, then increase the calculated BMR by 30% • If the person is active, then increase the calculated BMR by 40% • If the person is highly active then increase the calculated BMR by 50% Program Specification: Write a program that allows the user to input their weight in pounds, height in inches, and age in years. Ask the user to input the string “M” if the user is a man and “W” if the user is a woman. Use only the male formula to calculate calories if “M” is entered and use only the women formula to calculate calories if “W” is entered. Ask the user if he or she is: A. Inactive B. Somewhat active (exercise occasionally) C. Active (exercise 3-4 days per week) D. Highly active (exercise every day) • If the user answers “Inactive” then increase the calculated BMR by 20 percent. • If the user answers “Somewhat active” then increase the calculated BMR by 30 percent. • If the user answers “Active” then increase the calculated BMR by 40 percent. • Finally, if the user answers “Highly active” then increase the calculated BMR by 50 percent. • The program should then output the calculated daily Calories intake for this person in order to lose one pound per week by subtracting 500 calories from the calculated BMR. Input Errors • If the user enters an age either < 1 or > 100, instantly end the program with an error message. • If the user enters a height < 10 or > 100, instantly end the program with an error message. • If the user enters a weight < 10 or > 500, instantly end the program with an error message. • You can assume that the user does not type some non-numeric value. You don't have to test for this kind of non-numeric error. • If the user does not enter ‘M' for male calculation or 'W' for female calculation, instantly end the program with an error message. • If the user does not enter A, B, C, or D when prompted, instantly end the program with an error message. These limits must be defined as symbolic constants, which should be used throughout the program. Rules: • For this assignment you are limited to the Java features in Chapters 1 through 3; you are not allowed to use more advanced features to solve the problem. Please do not use Java features that are not covered in lecture or the textbook. • Use class constants as appropriate to represent important fixed data values in your program. • Follow programming guidelines and Java’s naming standards about the format of ClassNames, variableNames, and CONSTANT NAMES. • Notice that all real numbers output by the program are printed with no more than 2 digits after the decimal point. To achieve this, you may use the System.out.printf method. • Add the header to the class file and copy/paste the output that is produced by your program into the bottom of the source code file, making it into a block comment. • Class Name: Your program class should be called CalorieCalculator.

In: Computer Science

Hello I need a small fix in my program. I need to display the youngest student...

Hello I need a small fix in my program. I need to display the youngest student and the average age of all of the students. It is not working Thanks.

#include <iostream>

#include <iomanip>

#include <fstream>

#include <vector>

#include <algorithm>

using namespace std;

struct Student {

string firstName;

char middleName;

string lastName;

char collegeCode;

int locCode;

int seqCode;

int age;

};

struct sort_by_age {

inline bool operator() (const Student& s1, const Student& s2)

{

return (s1.age < s2.age); // sort according to age of student

}

};

// main function to run program

int main() {

//CHANGE: vector students; TO vector students;

vector<Student> students; // create vector object to hold students data

ifstream Myfile; // create input file stream object

Myfile.open("a2data.txt"); // open file

// check if file is open

if (!Myfile.is_open()) {

// display error message if file could not be opened

cout << "Could not open the file!";

return 0; //terminate

}

//CHANGE: vector words; TO vector words;

vector<string> words; // create vector object to store words from input file

//read input from file line by line

string line;

while (!Myfile.eof()) {

getline(Myfile, line); // readline from input file stream

line.c_str(); // convert string in to char array

// file given in eample does not contain one record each line

// but it hase some patern for reading

// each word is seprated by space

//read the liine till space is encountered and get the word

int i = 0; // iterator to iterate over line

string word = "";

while (line[i] != '\0') {

// loop till end of line

if (line[i] != ' ') {

word = word + line[i]; // build word with char

i++;

}

else {

if(word!="")

words.push_back(word); // add word to vector

word = ""; //reset word to empty string

i++; //ignore white space

}

}//end of line

words.push_back(word); // add word to vector

}//end of file

//when done reading input from file close the file stream

Myfile.close();

int count = 0; // counts the words proceesed from vector object words

string fname = words.at(count); // variable to store first name of student

count++; //move to next element in the vector

//CHANGE: count < words.size() TO count < words.size() - 2

// at least two words are read in an iteration, so at least two should remain to be read - last name + student id

while (count < words.size() - 2) {

// loop till end of vector words

// create student object

Student s;

//assign first name to student

s.firstName = fname;

//next element in words is middle name

//assign first char to middle name

string mname = words.at(count);

s.middleName = mname[0];

count++;

//next element is last name of student

//assign next word to student

s.lastName = words.at(count);

//CHANGE: start

//If there was no middle name, this is the student id + first name of next student

if(words.at(count).size() >= 12) // college code + locCode + seq + age

{

if(words.at(count)[1] >= '0' && words.at(count)[1] <= '9') // if second character is a digit

{

// this is the student id field, and there is no middle name

count --; // move one step back for next iteration

s.middleName = ' '; //blank middle name

s.lastName = words.at(count);

}

}

//CHANGE: end

count++;

//next element is student id + first name of next student

//id contains college code at first latter

string id = words.at(count);

count++;

//assign college code to the student

s.collegeCode = id[0];

//next 2 char in id contain location

string loc = "";

loc = loc + id[1];

loc = loc + id[2];

// assign location to student

s.locCode = stoi(loc); // convert string to integer

//next 6 char in id contain seqcode

string seq = "";

for (int j = 3; j < 9; j++) {

seq = seq + id[j];

}

// assign seqcode to student

s.seqCode = stoi(seq); //convert string to int

//next 3 char in id contains age

string age = "";

age = age + id[9];

age = age + id[10];

age = age + id[11];

//assign age to student

s.age = stoi(age); // convert string to int

//remainig latters in id contains next student's first name

// delete id of previous student to get name of next student

fname = id.erase(0, 12); // delete first 12 char from id and assign remaining to fname

// add student to student

students.push_back(s);

}

// clear the vector as done working with words

words.clear();

//sort vector according to age of students

sort(students.begin(), students.end(), sort_by_age());

// formating output

cout << setw(15) << left << "Last Name";

cout << setw(15) << left << "Midlle Name";

cout << setw(15) << left << "First Name";

cout << setw(15) << left << "College Code";

cout << setw(12) << left << "Location";

cout << setw(12) << left << "Sequence";

cout << setw(12) << left << "Age" << endl;

cout << "=======================================================================================" << endl;

// print all students

for (int i = 0; i < students.size(); i++) {

cout << setw(15) << left << students.at(i).lastName;

cout << setw(15) << left << students.at(i).middleName;

cout << setw(20) << left << students.at(i).firstName;

cout << setw(13) << left << students.at(i).collegeCode;

cout << setw(10) << left << students.at(i).locCode;

cout << setw(12) << left << students.at(i).seqCode;

cout << students.at(i).age << endl;

}

//print average age

cout << endl;

  

int avg_age = ageCalc(arry, youngest);

cout<<"Average age is: "<<avg_age<<endl;

cout<<"Youngest student is "<<youngest->firstName<<" "<<youngest->MiddleN<<" "<<youngest->LastN<<endl;

for(int i=0; i<index; i++){

delete arry[i];

}

return 0;

}

int ageCalc(Student *studs[], Student *&youngest){

youngest = studs[0];

int i = 0;

int avg_age = 0;

while(studs[i]!=NULL){

avg_age += studs[i]->age;

if(youngest->age>studs[i]->age)

youngest = studs[i];

i++;

}

return avg_age/i;

}

File needed:

https://drive.google.com/file/d/15_CxuGnFdnyIj6zhSC11oSgKEYrosHck/view?usp=sharing

In: Computer Science

Iterative Merge Sort is not working #include #include #include int* b; void merge(int a[], int left,...

Iterative Merge Sort is not working

#include
#include
#include
int* b;
void merge(int a[], int left, int mid, int right)
{
   int i = left, j = mid + 1, k = left;

   while (i <= mid && j <= right)
   {
       if (a[i] < a[j])
           b[k++] = a[i++];
       else
           b[k++] = a[j++];
   }
   for (; i <= mid; i++)
   {
       b[k++] = a[i];
   }
   for (; j <= right; j++)
   {
       b[k++] = a[j];
   }
   for (int i = left; i <= right; i++)
   {
       a[i] = b[i];
   }

}
void mergesort(int a[], int n)
{
   int p, left, right, mid, i;
   for (p = 2; p <= n; p = p * 2)
   {
       for (i = 0; i + p - 1 < n; i = i + p)
       {
           left = i;
           right = i + p - 1;
           mid = (left + right) / 2;
           merge(a, left, mid, right);
       }
   }
   if (p / 2 < n)
   {
       merge(a, 0, (p / 2) - 1, n - 1);
   }
}
void main()
{
   int max, * a;
   scanf("%d", &max);
   a = (int*)malloc(sizeof(int) * max);
   b = (int*)malloc(sizeof(int) * max);
   for (int i = 0; i < max; i++)
   {
       scanf("%d", &a[i]);
   }
   mergesort(a, max);
   for (int i = 0; i < max; i++)
   {
       printf(" %d", a[i]);
   }
}

input 50

50 49 48 47 46 45 ~ 5 4 3 2 1

output

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 2 19 20 21 22 23 24 ~ 50

why 1,2 are between in 18 and 19?

please answer and correct code

In: Computer Science

1 Please answer the following: a) Rank the following storage systems from slowest to fastest: a....

1 Please answer the following:

a) Rank the following storage systems from slowest to fastest: a. Hard-disk drives b. Registers c. Optical disk d. Main memory e. Nonvolatile memory f. Magnetic tapes g. Cache

b) How are iOS and Android similar? How are they different?

In: Computer Science

Write a Python program that reads in an amount in cents and prints the dollar amount...

Write a Python program that reads in an amount in cents and prints the dollar amount in that and the remaining value in cents. For example, if the amount reads in is 360 (cents), the program would print 3 dollars and 60 cents. if the amount read in is 75 (cents), the program would print 0 dollars and 75 cents.

In: Computer Science

C++ How would I sort my output to evaluate it by sorting the column by it's...

C++

How would I sort my output to evaluate it by sorting the column by it's size? I didn't include my full program but here is the main.cpp where i'm supposed to sort the output by column size.

//User Libraries
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;

//User Libraries
#include "Table.h"
#include "Triangle.h"

//Global Constants

//Function Prototype
void prntRow(RowAray *,int);
void prntTab(Table *);
void prntTri(Triangle *);


//Execution Begins Here!
int main(int argc, char** argv) {
//Initialize the random seed
srand(static_cast<unsigned int>(time(0)));

//Declare Variables
// creates a random number of rows from 1 to 10
int rows=(rand()%10)+ 1;
//creates a random number of columns from 1 to 10
int cols=(rand()%10 )+1;
int perLine=cols/2;

//Test out the RowAray
RowAray row(cols);
  
//Print the RowAray
cout<<"The Row Array size = "<<row.getSize()
<<" printed "<<perLine<<" per Line";

prntRow(&row,perLine);


//Test out the Table
Table tab(rows,cols);

//Print the Table
cout<<"The table size is [row,col] = ["<<rows<<","<<cols<<"]";
prntTab(&tab);

//Test out the Triangular Table
Triangle tri(rows);

//Print the Triangular Table
cout<<"The triangular table size is [row,row] = ["<<rows<<","<<rows<<"]";
prntTri(&tri);

//Exit Stage Right
return 0;
}

//Fill a triangular matrix
int **fillAry(int *col,int n){
int **array=new int*[n];
for(int i=0;i<n;i++){
array[i]=new int[col[i]];
}
for(int i=0;i<n;i++){
for(int j=0;j<col[i];j++){
array[i][j]=rand()%9+1;//1 Digit numbers [1-9]
}
}
return array;
}
void prntRow(RowAray *a,int perLine){
cout<<endl;
for(int i=0;i<a->getSize();i++){
cout<<a->getData(i)<<" ";
if(i%perLine==(perLine-1))cout<<endl;

}
cout<<endl;
}

void prntTab(Table *a){
cout<<endl;
for(int row=0;row<a->getSzRow();row++){
for(int col=0;col<a->getSzCol();col++){
cout<<a->getData(row,col)<<" ";
}
cout<<endl;
}
cout<<endl;
}

void prntTri(Triangle *a){
cout<<endl;
for(int row=0;row<a->getSzRow();row++){
for(int col=0;col<=row;col++){
cout<<a->getData(row,col)<<" ";
}
cout<<endl;
}
cout<<endl;
}

In: Computer Science

Explain the similarities and differences between spiders, crawlers and bots in relation to search engines. Additionally...

Explain the similarities and differences between spiders, crawlers and bots in relation to search engines. Additionally with the Search Engine Optimization elements (SEO); explaining the terms positioning and placement as they relate to SEO, with examples.

In: Computer Science

Cpp challenge Description The purpose of this challenge is to use the WHILE loop to control...

Cpp challenge

Description

The purpose of this challenge is to use the WHILE loop to control program flow. This challenge will use the WHILE loop in various ways.

Requirements

Write all your code for the following steps in one file.

  1. Ask the user to enter a single string. Ask the user to enter an integer value for a variable called repetitions. Use a while loop to display this string (of your choice) repeated repetitions times, one string per line
  2. Use a while loop to count and display all the integers from 1 to 20. Separate numbers with a space
  3. Use a while loop to display all numbers divisible by 10 starting from 100 down to 0. Only show numbers divisible by 10. Separate numbers with a tab. TAB character is displayed using the \t escape sequence. (Remember that \n is a newline; use similarly)
  4. Use a while loop to keep asking the user for an integer as long as positive numbers are being entered. For every positive number entered, show its value multiplied by 2. Once a negative number is entered stop asking and quit the loop
  5. Use a while loop to keep asking for a string until a particular string is entered (for example, “bye”)

    Do Not Use

    You must use the WHILE statement. You may not use any other looping mechanism.

Sample Interaction / Output

Enter a string to be repeated: coffee
How many times to show? 5

coffee
coffee
coffee
coffee
coffee

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

100  90   80   70   60   50   40   30   20   10 

Enter a number: 3
3 x 2 = 6
Enter a number: 7
7 x 2 = 14
Enter a number: -2

Enter a string: yo
Enter a string: hi
Enter a string: hola
Enter a string: sup
Enter a string: bye

In: Computer Science

In C++ Prompt user to enter two integers •Determine whether the first number is divisible by...

In C++

Prompt user to enter two integers

•Determine whether the first number is divisible by the second. If the second number is zero, the program should not do division

•Output the remainder of the two numbers

•Compare the two integers, display the integers in non-decreasing order.

In: Computer Science

public class IntNode               {            private int data;            pri

public class IntNode      
        {
           private int data;
           private IntNode link;
           public IntNode(int data, IntNode link){.. }
           public int     getData( )          {.. }
           public IntNode getLink( )           {.. }
           public void    setData(int data)     {.. }
           public void    setLink(IntNode link) {.. }
        }

All questions are based on the above class, and the following declaration.  

// Declare an empty, singly linked list with a head and a tail reference.

// you need to make sure that head always points to the head node and tail always points to the tail node.
         IntNode head, tail;
         head = tail = null;    

// 1.) Insert a node with data 2 into this empty list

// 2.) Insert a node with data 4 at the end of the list.

// 3.) Insert a node with data 3 between the first and the last node.

// 4.) Insert a node with data 1 before the first node.

// 5.) delete the node with data 2

// 6.) delete the node with data 1

In: Computer Science

1. Explain the important areas that need to be considered for a migration of web or...


1. Explain the important areas that need to be considered for a migration of web or mail services to the cloud. Why are these areas important?

2. The cloud computing model can lead to privacy compliance concerns. Provide examples of these concerns, and an analysis of the types of actions that you might take to mitigate these concerns.


5. What cloud computing best practices would you propose adopting? Why?

In: Computer Science

SUBJECT: CYBER ESSENTIALS Convert between binary and hexadecimal values Question 7: Convert binary number to a...

SUBJECT: CYBER ESSENTIALS

Convert between binary and hexadecimal values

Question 7: Convert binary number to a hexadecimal number

Binary number: 00001100

Hexadecimal value: ??

Question 8: Convert binary number to a hexadecimal number

Binary number: 01001111

Hexadecimal value: ??

Question 9: Convert binary number to a hexadecimal number

Binary number: 10101101

Hexadecimal value: ??

Question 10: Convert hexadecimal number to an 8 bit binary number

Hexadecimal number: AB

8 bit binary number:

Question 11: Convert hexadecimal number to an 8 bit binary number

Hexadecimal number: D2

8 bit binary number: ??????????

Question 12: Convert hexadecimal number to an 8 bit binary number

Hexadecimal number: 01

8 bit binary number: ??????????

Part 3: ASCII Code (10 points)

Question 13: What character is the hexadecimal ASCII code 23?

Question 14: What character is the hexadecimal ASCII code 4A?

Question 15: What character is the hexadecimal ASCII code 6A?

Part 4: Converting numbers to binary (20 points)

Question 16: For each scenario determine if the numbers should be stored as ASCII codes or binary equivalents. Then find the ASCII code or calculate the binary equivalent.

Scenario

ASCII code

Binary equivalent

The course number: 107

The year: 2001

The number of printers in inventory: 62

The weight of a suitcase when it is checked in at the airport: 24

Question 17: Explain your reason for each of the choices in the previous question.

Scenario

Binary equivalent

The course number: 107

The year: 2001

The number of printers in inventory: 62

The weight of a suitcase when it is checked in at the airport: 24

In: Computer Science

Write a Reverse Polish Calculator, RPN in JAVA Each time an operand is encountered, two values...

Write a Reverse Polish Calculator, RPN in JAVA

Each time an operand is encountered, two values are popped from this stack, the given operation is performed, and the result is pushed back onto the stack. Utilize Java generic Stack Class to implement this algorithm with four arithmetic operations: +, *, -, /.

Implement a class RPN with a single static method evaluate. This method should have the following signature:

            public static String evaluate(String expression)

It should split the passed expression into (a string array of) tokens by invoking split method of String class. This array can then be processed one element at a time (perhaps another method): each time a number is found – it is pushed on a stack. Each time an operation is found – two numbers are popped from the stack, the given operation is performed, and the result is pushed back on the stack. If the passed expression was a properly formed RPN, the last element on the stack represents the result. It should be returned as a string. If the given expression is not valid, evaluate should return a string denoting a syntax error.

Your main should continually ask the user to input a potential RPN string which would be passed to the evaluate method. In order to terminate the procedure, the user would input an empty string (carriage return).

Sample run of how it should look:

run:

Enter an RPN expression or to exit

2 3 4 +

7.0

extra junk ignored

Enter an RPN expression or to exit

2 3 4 + *

14.0

Enter an RPN expression or to exit

2 3 + +

Syntax error

Enter an RPN expression or to exit

10 6 1 - /

2.0

Enter an RPN expression or to exit

5 4 3 / /

3.75

Enter an RPN expression or to exit

  

good bye

In: Computer Science

Create an application that calculates and displays the starting and ending monthly balances for a checking...

Create an application that calculates and displays the starting and ending monthly balances for a checking account and a savings account.

Welcome to the Account application Starting Balances Checking: $1,000.00 Savings: $1,000.00 Enter the transactions for the month Withdrawal or deposit? (w/d): w Checking or savings? (c/s): c Amount?: 500 Continue? (y/n): y Withdrawal or deposit? (w/d): d Checking or savings? (c/s): s Amount?: 200 Continue? (y/n): n Monthly Payments and Fees Checking fee: $1.00 Savings interest payment: $12.00 Final Balances Checking: $499.00 Savings: $1,212.00.

  • Create interfaces named Depositable, Withdrawable, and Balanceable that specify the methods that can be used to work with accounts. The Depositable interface should include this method:

void deposit(double amount)

The Withdrawable interface should include this method:

void withdraw(double amount)

And the Balanceable interface should include these methods:

double getBalance()
void setBalance(double amount)

  • Create a class named Account that implements all three of these interfaces. This class should include an instance variable for the balance.
  • Create a class named CheckingAccount that inherits the Account class. This class should include an instance variable for the monthly fee that’s initialized to the value that’s passed to the constructor. This class should also include methods that subtract the monthly fee from the account balance and return the monthly fee.
  • Create a class named SavingsAccount that inherits the Account class. This class should include instance variables for the monthly interest rate and the monthly interest payment. The monthly interest rate should be initialized to the value that’s passed to the constructor. The monthly interest payment should be calculated by a method that applies the payment to the account balance. This class should also include a method that returns the monthly interest payment.
  • Create a class named AccountBalanceApp that uses these objects to process and display deposits and withdrawals.
  • Use the Console class presented in chapter 7 or an enhanced version of it to get and validate the user’s entries. Don’t allow the user to withdraw more than the current balance of an account.

sorry to bother i really appreciate the help could you explain step by step please and thank you.

In: Computer Science

############callbacks ##def function_1( x ) : return x ** 2 ##def function_2( x ) : return...

############callbacks

##def function_1( x ) : return x ** 2
##def function_2( x ) : return x ** 3
##def function_3( x ) : return x ** 4
##
###### create a list of callbacks to each of the functions
######by referencing their names
##
##callbacks = [ function_1 , function_2 , function_3 ]
##
######display a heading and the result of passing a value to each of the
######named functions:
##
##print( '\nNamed Functions:' )
##for function in callbacks : print( 'Result:' , function( 3 ) )
##
####Task 3. Run the code above. Understand it. Display callback for
####the situation when you need to run 2*function_1, 2*function_2,2*function_3,
####for x = 10, show that your code works.

In: Computer Science