Question

In: Computer Science

1. Write the C++ code for a program that calculates how many days are left until...

1. Write the C++ code for a program that calculates how many days are left until Halloween, when given as an input how many weeks are left until Halloween. Use variables named weeks and days.

------------

2. What header file must be included

- To perform mathematical functions like sqrt?

- To use cin and cout?

- To use stream manipulators like setprecision?

--------------------

3. What value will be stored in the variable t after each of the following statements executes?

1. t = (12 > 1);

2. t = (2 < 0);

3. t = (5 == (3 * 2));

4. t = ( 5 == 5);

----------------

4. Convert the following conditional expression into an if/else statement:
q = (x < y) ? (a+b) : (x * 2);

------------------

5. Write a function named getNumber which uses a reference parameter to accept an integer argument. The function should prompt the user to enter a number in the range of 1 through 100. The input should be validated and stored in the parameter value.

------------------------

6. Write a C++ statement that prints the message “The number is valid.” If the variable temperature is within the range -50 through 150

Solutions

Expert Solution

Code:

#include<iostream>
using namespace std;
int main(){
//   declare variables
   int weeks,days;
  
//   take input from user number of weeks
   cout<<"Enter number of Weeks left until Halloween : ";
   cin>>weeks;
  
//   calculate number of days
   days = 7*weeks;
  
//   print the days
   cout<<endl<<days<<" days are left until Halloween";

   return 0;
}

Code::

#include<iostream>
using namespace std;

//functin that reads the data from user
void getNumber(int *n){
   int x;
   cout<<"Enter a number in the range of 1 through 100. : ";
   cin>>x;
   if(x>=1 || x<=100){
      
       *n = x;
   }
  
  
}

int main(){
  
   int n;
  
//   call the function getNumber pass the reference of n
   getNumber(&n);
  
   return 0;
}

Code:

#include<iostream>
using namespace std;
int main(){
  
   int temp;
  
//   prompt the user for number
   cin>>temp;
  
//   check if the number is in range of -50 to 150
  
   if(temp>=-50 && temp<=150){
      
       cout<<"The number is valid.";
   }
  
   return 0;
}


Related Solutions

C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is...
C# CODE C# 1) Write a program that calculates a student's GPA. Remember, an A is worth 4 points, a B is worth 3 points, a C is worth 2 points, a D is worth 1 point, and an F is worth 0 points. For the purposes of this assignment, assume that all classes carry the same number of credit hours. 2) Use a sentinel-controlled loop to gather a variable number of letter grades. This should terminate the loop if...
PROBLEM: c++ code You are to write a program to tell you how many months it...
PROBLEM: c++ code You are to write a program to tell you how many months it will take to pay off a loan, as well as the total amount of interest paid over the life of the loan. You have just purchased a stereo system that costs $1000 on the following credit plan: No down payment, an interest rate of 18% per year (and hence 1.5% per month), and monthly payments of $50. The monthly payment of $50 is used...
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the...
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the average CPI, total processing time (T), and MIPS of a sequence of instructions, given the number of instruction classes, the CPI and total count of each instruction type, and the clock rate (frequency) of the machine. The following is what the program would look like if it were run interactively. Your program will read values without using prompts. Inputs: • Clock rate of machine...
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the...
Programming Assignment 1 Performance Assessment Objective: To write a C program (not C++) that calculates the average CPI, total processing time (T), and MIPS of a sequence of instructions, given the number of instruction classes, the CPI and total count of each instruction type, and the clock rate (frequency) of the machine. The following is what the program would look like if it were run interactively. Your program will read values without using prompts. Inputs: • Clock rate of machine...
make a c++ program that calculates the amount left from a value of money of one...
make a c++ program that calculates the amount left from a value of money of one dollar bill or less in quarters, dimes, nickels, and pennies. The remaining value can be shown in cents knowing that in cents: penny = 1 nickel = 5 dime = 10 quarter = 25
Your task is to write a program in C or C++ that calculates the total amount...
Your task is to write a program in C or C++ that calculates the total amount of money a person has made over the last year. Your program will prompt the user for dollar amounts showing how much the user has made per job. Some users will have had more than one job, make sure your program allows for this. The program will print out the total made (all jobs) and will print out the federal and state taxes based...
Project 1: Frequent Flyer Miles Calculator Write a Ruby program that calculates how many frequent flyer...
Project 1: Frequent Flyer Miles Calculator Write a Ruby program that calculates how many frequent flyer miles are needes for a free ticket on a new startup airline, CorsairAir. Frequent flyer miles are charged for a free ticket depending on the class of service (more for first class, less for coach), depending on the day flying (more if flying on Friday, Saturday or Monday, less for other days of the week), depending on the distance traveled, and a surcharge if...
Question: How do I write a program in C# that calculates a student's final grade for...
Question: How do I write a program in C# that calculates a student's final grade for a test with 20 multiple questions using arrays and helper methods? Instructions: (0-incorrect answer, 1-correct answer) If the student answered the question right, add .5 points to the running total. If the student didn’t answer correctly subtract .5 points from the running total. The running total is initialized with 5 points (so the student receives 5 points extra credit). To define the final grade...
Write java program that reads daily sales for 30 days until -1 is entered and find...
Write java program that reads daily sales for 30 days until -1 is entered and find and display the following: a) average sales for 30 days. b) number of days that daily sales over $5000.00             
Write a program that calculates how many digits an integer value acquired via scanf() contains. A...
Write a program that calculates how many digits an integer value acquired via scanf() contains. A correctly functioning program should produce the following output, where the user entered the value 374: Enter a number:  374 The number 374 has 3 digits You may assume that the input integer has no more than four digits. Use if statements to test the number. For example, if the integer value entered by the user is between 0 and 9, it has one digit. If...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT