answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
dlinn [17]
1 year ago
9

Write a program that prints the U.S. presidential election years from 1792 to present day, knowing that such elections occur eve

ry 4 years.
Computers and Technology
1 answer:
miv72 [106K]1 year ago
4 0

Answer:

The cpp program to print US presidential years is given.

#include <iostream>

using namespace std;

int main()

{

   // variable to hold presidential election year declared  

   int elec_year;

// variable to hold presidential election year initialized to 1792  

elec_year=1792;

   

// the value displayed on the console output

   std::cout << "The U.S. presidential election years from 1792 to present day are listed. " << std::endl;

   

   // loop executes till year is less than or equals 2020

   do

   {

       // initial value is printed

       std::cout << elec_year << std::endl;

       

       // value is incremented by 4

       elec_year = elec_year + 4;

       

   }while(elec_year<=2020);

   return 0;

}

OUTPUT

The U.S. presidential election years from 1792 to present day are listed.  

1792

1796

1800

1804

1808

1812

1816

1820

1824

1828

1832

1836

1840

1844

1848

1852

1856

1860

1864

1868

1872

1876

1880

1884

1888

1892

1896

1900

1904

1908

1912

1916

1920

1924

1928

1932

1936

1940

1944

1948

1952

1956

1960

1964

1968

1972

1976

1980

1984

1988

1992

1996

2000

2004

2008

2012

2016

2020

Explanation:

The program works as described.

1. An integer variable, elec_year, is declared and initialized with the first US presidential year value, 1792.

2. Inside the do-while loop, the variable, elec_year, is first printed to the console followed by a new line inserted using, endl.

3. The variable, elec_year, is then incremented by 4.

4. The do-while loop continues till the value of the variable, elec_year, does not exceeds the current year, 2020.

5. The program ends with a return statement since main() has return type int.

6. Only one variable is used in the program.

7. The program consists of only main() method since cpp is not completely object oriented programming language.

8. The same program, if written in object oriented programming language like java or c# will be written inside a class and executed through main() method.

You might be interested in
To gain experience of using and combing different sorting algorithms: election sort, insertion sort, merge sort, and quick sort.
ch4aika [34]

Answer:

Motivation? The search problem.

Sorting algorithms: insertion sort, shellsort, heapsort, mergesort, quicksort, bubblesort

At the very least, "general purpose" sorting algorithms require O(n log n) comparisons

Explanation:

3 0
2 years ago
Write a function that implements another stack function, peek. Peek returns the value of the first element on the stack without
devlian [24]

Answer:

See explaination

Explanation:

StackExample.java

public class StackExample<T> {

private final static int DEFAULT_CAPACITY = 100;

private int top;

private T[] stack = (T[])(new Object[DEFAULT_CAPACITY]);

/**

* Returns a reference to the element at the top of this stack.

* The element is not removed from the stack.

* atreturn element on top of stack

* atthrows EmptyCollectionException if stack is empty

*/

public T peek() throws EmptyCollectionException

{

if (isEmpty())

throw new EmptyCollectionException("stack");

return stack[top-1];

}

/**

* Returns true if this stack is empty and false otherwise.

* atreturn true if this stack is empty

*/

public boolean isEmpty()

{

return top < 0;

}

}

//please replace "at" with the at symbol

Note:

peek() method will always pick the first element from stack. While calling peek() method when stack is empty then it will throw stack underflow error. Since peek() method will always look for first element ffrom stack there is no chance for overflow of stack. So overflow error checking is not required. In above program we handled underflow error in peek() method by checking whether stack is an empty or not.

3 0
2 years ago
Which type of utp cable is used to connect a pc to a switch port?
rodikova [14]
HDMI Cable, i think that's what it's called.
3 0
2 years ago
Constantine forms the following hypothesis. Let n be any non-negative number that meets the following condition: when n is divid
notka56 [123]

Answer:

n=5

Explanation:

if n= 5

i.     n/5=5/5=1  so it divides completely the remainder is 0

ii.  97 - 6(5) = 97 - 30 = 67,   67 is a prime number.

8 0
2 years ago
Given that a method receives three parameters a, b, c, of type double, write some code, to be included as part of the method, th
Debora [2.8K]

Answer and Explanation:

class Dis

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.println("Enter values for a,b,c");

double a=sc.nextDouble();

double b=sc.nextDouble();

double c=sc.nextDouble();

String s=discriminant(a,b,c);

System.out.println(s);

}

public String discriminant(double a, double b, double c)

{

double result;

result=(b^2-4ac);

if(result<0)

return "no real solutions"";

else return "";

}

}

Note:This program is written in JAVA

6 0
1 year ago
Read 2 more answers
Other questions:
  • When you examine a computer chip under a microscope, what will you see?
    6·1 answer
  • The term drive app is used to describe applications stored on a computer true or false
    11·2 answers
  • Which of the following commands uses correct syntax for matching the patterns bunk or bank at the end of a line of text?
    5·1 answer
  • If you are viewing a webpage with customized or regenerated content, such as updated stock quotes, what type of webpage are you
    5·1 answer
  • Together with some anthropologists, you’re studying a sparsely populated region of a rainforest, where 50 farmers live along a 5
    15·1 answer
  • Given an int variable k, an int array incompletes that has been declared and initialized, an int variable studentID that has bee
    10·1 answer
  • .Ten pounds of candy were prepared for the school party.
    10·1 answer
  • 1. Write a set of routines for implementing several stacks and queues within a single array. Hint: Look at the lecture material
    15·1 answer
  • You have an on-premises network that contains several servers. You plan to migrate all the servers to Azure. You need to recomme
    14·1 answer
  • Write an expression to print each price in stock prices.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!