Question

In: Computer Science

write pseudocode for the following problems using if while conditions A student buys various books at...

write pseudocode for the following problems using if while conditions

A student buys various books at the start of the semester from a bookshop. Write pseudocode for a program which takes the total amount spent on books and the total number of books as input and outputs the average cost per book.


Write pseudocode for a program which takes a year as input (e.g. 2014) and determines whether or not it is a leap year. A leap year is a multiple of 4, and if it is a multiple of 100, it must also be a multiple of 400.


Write pseudocode for a program which takes 3 integer values, a b c, as input and prints their sum. However, if one of the values is the same as another of the values, it does not count towards the sum.


When squirrels get together for a party, they like to have nuts. A squirrel party is successful when the number of nuts is between 40 and 60, inclusive. Unless it is the weekend, in which case there is no upper bound on the number of nus. Write pseudocode of a program which inputs the number of nuts consumed at a party, and prints “True” if the party with the given values is successful, or “False” otherwise.


Write pseudo code that will perform the following. 


Read in 5 separate numbers.


Calculate the average of the five numbers.


Find the smallest (minimum) and largest (maximum) of the five entered numbers.


Write out the results found from steps b and c with a message describing what they are.


Write pseudo code that reads in three numbers and writes them all in sorted order.


You are driving a little too fast, and a police officer stops you. Write pseudocode to compute the result, encoded as an integer value: 0=no ticket, 1=small ticket, 2=big ticket. If speed is 60 or less, the result is 0. If speed is between 61 and 80 inclusive, the result is 1. If speed is 81 or more, the result is 2. Unless it is your birthday -- on that day, your speed can be 5 higher in all cases.


Write pseudocode for a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.


Iterations

Write a loop to print this fencepostpattern. Such fencepost loops can be created by placing one post (i.e. |) outside your loop, and then alternating between wires (i.e. ==) and posts inside the loop.


|==|==|==|==|

Write pseudocode for a program that takes an integer and uses a fencepost loop to print the factors of that number, separated by the word "and". For example, for the number 24, it should print the following output.


1 and 2 and 3 and 4 and 6 and 8 and 12 and 24

Write pseudocode for a program which repeatedly reads integers from the user, stopping only when the user enters -1, and returns the largest value input.


write a program that calculates the sum of numbers entered by a user one at a time. The program terminates when user enters -1.

Write pseudcode for a program that calculates the area of simple shapes. The Shape given as input can be circle, square, or right triangle.


Extend the previous program such that the users can calculate the area (of the 3 specified shapes) as many times as they want. 


Write PC that takes in a +ve number N and prints the square of size N composed of '*'.


Write PC that takes in a +ve number N and determines if it is a prime or not. 


Q4.   can be calculated from the infinite series given below: 

=4- 43+ 45- 47+ 49- 411+

Write a pseudo code that prints the value of after the first 100 terms, 200 terms and 300 terms. Write one pseudo code that prints all three values. Don’t write 3 different codes. 

Write a program that takes in a +ve integer and prints its break up in terms of units, tens, hundreds etc. The number is not longer than 4 digits.


Input 2000        Output: 0 units, 0 tens, 0 hundreds, 2 thousands

Input 173        Output: 3 units, 7 tens, 1 hundreds

Write a program to output the individual digits of a number from right to left with spaces added in between each digit. For example if the number is 9867 then your program should output: 7 6 8 9 

 Repeat the above so that the digits are printed from left to right. For example for 9867 the output should be 9 8 6 7. The maximum number you have to cater for is 105. The leading zeros should NOT be printed so if the number is 105 the output should be 1 0 5 and NOT 0 0 0 1 0 5. 



Write a program that inputs numbers from the user till the user inputs a negative number. The program should then print the second maximum of all numbers and second minimum of all numbers that were input. The last negative number should not count towards the minimum. For example if the input is: 10 7 42 2 2 0 56 6 -1 


The output should be: second maximum is 10 and second minimum is 2

Solutions

Expert Solution

#include<iostream>

#include<iomanip>

using namespace std;

int main(){

    float number_of_books;

    float total_cost;

    cout<<"Enter total amount spent on books"<<endl;

    cin>>total_cost;

    cout<<"Enter number of books"<<endl;

    cin>>number_of_books;

    float average = total_cost/number_of_books;

    cout<<fixed<<setprecision(2)<<average;

    return 0;

}

//---------------------leap year

#include <iostream>

using namespace std;

int main()

{

    int year;

    cout << "Enter a year: ";

    cin >> year;

    if (year % 4 == 0) {

        if (year % 100 == 0)   {

            if (year % 400 == 0)

                cout << year << " is a leap year.";

            else

                cout << year << " is not a leap year.";

        }

        else

            cout << year << " is a leap year.";

    }

    else

        cout << year << " is not a leap year.";

    return 0;

}

//----------------------------

//sum of three numbers

#include <iostream>

using namespace std;

int main()

{

    int a, b, c;

    cin >> a >> b >> c;

    int sum = a + b + c;

    if (a == b && a != c)

    {

        sum = sum - a;

    }

    if (a == c && a != b)

    {

        sum = sum - a;

    }

    if (b == c && a != c)

    {

        sum = sum - b;

    }

    if (a == b && a == c)

    {

        sum = a;

    }

  cout<<"Sum :- "<<sum;

    return 0;

}

//-------------------------------------------

//nuts party

#include <iostream>

using namespace std;

int main()

{

    int number_of_nuts;

    cout << "Enter the number of nuts consumed at a party" << endl;

    cin >> number_of_nuts;

    if (number_of_nuts >= 40)

    {

        cout << "True";

    }

    else

    {

        cout << "False";

    }

    return 0;

}

//----------------

//-------------------------

// //five number operation

#include <iostream>

using namespace std;

int main()

{

    int arr[5];

    cout << "Enter five numbers" << endl;

    int i = 0;

    while (i < 5)

    {

        cin >> arr[i];

        ++i;

    }

    float average = 0;

    float sum = 0;

    i = 0;

    while (i < 5)

    {

        sum = sum + arr[i];

        ++i;

    }

    average = sum / 5;

    cout << "Average of given five numers :- " << average << endl;

    i = 1;

    int min = arr[0], max = arr[0];

    while (i < 5)

    {

        if (min > arr[i])

            min = arr[i];

        if (max < arr[i])

            max = arr[i];

        ++i;

    }

    cout << "Minimum number :-" << min << endl;

    cout << "Maximum Number :-" << max << endl;

    return 0;

}

//-------------------------------

//three number sorting

#include<iostream>

using namespace std;

int main(){

    int array[5]; //here we are use array for easy way to sort number

    

    int n = 3;

    cout<<"enter three numbers"<<endl;

    int i=0;

    while (i<n) {

       cin>>array[i];

       ++i;  

    }

    //here am using bubble sort algorith

   for (int i = 0; i < n; i++)

   {

       for (int j = 0; j < n-1-i; j++)

       {

           if(array[j] > array[j+1])

            swap(array[j],array[j+1]);

       }

       

   }

   i = 0;

  

   cout<<endl<<"Sorted numbers"<<endl;

   //after sorting printing array of three numbers

    while (i<n)

   {

       cout<<array[i]<<" ";

       ++i;

   }

    return 0;

}

//for aother question, please post question again left question.


Related Solutions

write pseudocode for the following problems not c code Pseudocode only Write a C program to...
write pseudocode for the following problems not c code Pseudocode only Write a C program to print all natural numbers from 1 to n. - using while loop Write a C program to print all natural numbers in reverse (from n to 1). - using while loop Write a C program to print all alphabets from a to z. - using while loop Write a C program to print all even numbers between 1 to 100. - using while loop...
Write an algorithm in pseudocode for the binary search method using a while loop (iterative version)...
Write an algorithm in pseudocode for the binary search method using a while loop (iterative version) The recursive ternarySearch method returns true or false depending if the element was found or not. The ternarySearch method works in a similar manner to a binary search except it uses two mid values that “divide” the array into three portions. So, it needs to consider three recursive scenarios: See sample run: Accounts are: [0] 5658845 [1] 8080152 [2] 1005231 [3] 4520125 [4] 4562555...
Write an algorithm in pseudocode for the binary search method using a while loop (iterative version)...
Write an algorithm in pseudocode for the binary search method using a while loop (iterative version) The recursive ternarySearch method returns true or false depending if the element was found or not. The ternarySearch method works in a similar manner to a binary search except it uses two mid values that “divide” the array into three portions. So, it needs to consider three recursive scenarios: See sample run: Accounts are: [0] 5658845 [1] 8080152 [2] 1005231 [3] 4520125 [4] 4562555...
PCR; 4. A student is using the following PCR cycle conditions to amplify a 384 bp...
PCR; 4. A student is using the following PCR cycle conditions to amplify a 384 bp segment of DNA: i) incubate at 95oC for 30 seconds; ii) incubate at 53oC for 30 seconds; iii) incubate at 72oC for 40 seconds. (a) Describe what is happening during each step (i, ii, iii) of the PCR cycle. (b) After gel electrophoresis of the PCR products, the students see three bands (212 bp, 288 bp, 866 bp) in addition to the desired 384...
A student collected the following data while using the procedure described in this module: 27.13 mL...
A student collected the following data while using the procedure described in this module: 27.13 mL of 1.00 x 10^-2M EDTA soltuion was required to reach the ErioT end point for titration of 25.00 mL of the sample water. After boiling and filtering 100.00 mL of the water, the student diluted the filtrate to 100.0 mL with distilled water. To titrate 25.00 mL of the diluted filtrate, 26.40 mL of 2.00 x 10^-1 M EDTA solution was required. The studetn...
This lab examines the various ways of working with arrays by writing pseudocode. Read the following...
This lab examines the various ways of working with arrays by writing pseudocode. Read the following programming problem prior to completing the lab. The American Red Cross wants you to write a program that will calculate the average pints of blood donated during a blood drive. The program should take in the number of pints donated during the drive, based on a seven-hour drive period. The average pints donated during that period should be calculated and displayed. Additionally, the highest...
Using pseudocode or C++ code, write code to print “small” if the magnitude M of an...
Using pseudocode or C++ code, write code to print “small” if the magnitude M of an earthquake is in the range [0, 3), “medium” if M is in the range [3, 6), “large” if M is in the range [6, 9) and “epic” if M is greater than or equal to 9, where M is input by a user via the keyboard. (in c++)
Using pseudocode or C++ code, write a function to compute and return the product of two...
Using pseudocode or C++ code, write a function to compute and return the product of two sums. The first is the sum of the elements of the first half of an array A. The second is the sum of the elements of the second half of A. The function receives A and N ≥ 2, the size of A, as parameters. (in c++)
write JAVA code with the following condition Write the pseudocode for a new data type MyStack...
write JAVA code with the following condition Write the pseudocode for a new data type MyStack that implements a stack using the fact that you have access to a queue data structure with operations enqueue(), dequeue(), isEmpty(). Remember that every stack should have the operations push() and pop(). Hint: use two queues, one of which is the main one and one is temporary. Please note that you won’t be able to implement both push() and pop() in constant time. One...
Given the below pseudocode, write the proper code that implements it using MARIE's assembly language:               ...
Given the below pseudocode, write the proper code that implements it using MARIE's assembly language:                    Input a number and store it in X; if X > 1 then    Y := X + X;    X := 0; endif; Y := Y + 1; Output the value of Y; N.B: You should include the MARIE code in your Answer, with an explanation of each instruction in your code beside it. Example:              Subt One         /Subtract 1 from AC Add a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT