0% found this document useful (0 votes)
7 views2 pages

C++ Programming Assignment for Beginners

The document outlines an assignment for first-year pre-engineering students at Wollo University's Kombolcha Institute of Technology, focusing on C++ programming tasks. It includes various programming challenges such as computing powers, calculating letter grades, summing series, identifying prime numbers, and creating shapes. Each task is designed to enhance students' programming skills and understanding of C++ syntax and control structures.

Uploaded by

abebawshita04
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

C++ Programming Assignment for Beginners

The document outlines an assignment for first-year pre-engineering students at Wollo University's Kombolcha Institute of Technology, focusing on C++ programming tasks. It includes various programming challenges such as computing powers, calculating letter grades, summing series, identifying prime numbers, and creating shapes. Each task is designed to enhance students' programming skills and understanding of C++ syntax and control structures.

Uploaded by

abebawshita04
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Wollo University

Kombolcha Institute of Technology

Department: ______________________

Computer Programming (ECEg 1052) Assignment

Target group: 1st year pre-engineering students

Max Marks: 20%

1. Write a C++ program that compute 2n where, n is input from the user/keyboard.

2. Write a C++ program that can compute the letter grade of a student after accepting the student’s
mid and final mark. The program should only accept mid result [0-40] and final [0- 60]. If the data
entered violates this rule, the program should display that the user should enter the mark in the
specified range. The program is also expected to run until the user refuses to continue. Use the
following scale.

100 > X > 90 ----------------- > A


90 > X > 70 ------------------- > B
70 > X > 50 ------------------- > C
50 > X > 40 ------------------- > D
40 > X > 0 --------------------- > F
> 100 and < 0 -------------- > Invalid Input

3. Write a C++ code that computes the sum of the following series.

Sum = 1! + 2! + 3! + 4! + …n!

Note: The program should accept the number from the user.
4. A prime number is an integer greater than one and divisible only by itself and one. The first
seven prime numbers are 2, 3, 5, 7, 11, 13, and 17. Write a program that displays all the prime
numbers between 1 and 100.

5. Write a C++ program that accept a number and display the factor of that number.

6. Write C++ program using for, do-while, and while statements to compute the following sums
and products.

A. 1+2+3+…+100
B. 5+10+15+…+n
C. 2+4+6+…+n
D. 1*3*5*7…*20
7. Write a C++ program that will print the following shapes.
A. B. C. D.
* 54321 * *
** 4321 *** ***
*** 321 ***** *****
**** 21 ******* ***
***** 1 ********* *

8. Develop a calculator program that computes and displays the result of a single requested
operation.

E.g. if the input is

15 * 20, then the program should display 15 * 20 equals 300

If the operator is not legal, as in the following example

24~25 then the program displays ~ is unrecognized operator

As a final example, if the denominator for a division is 0, as in the following

Input: 23/0 then the program should display the following:

23 / 0 can’t be computed: denominator is 0

Common questions

Powered by AI

The program iteratively tests divisibility from 1 to the number itself, outputting values that divide evenly. An efficient approach tests up to the square root of the number, leveraging pair factors to reduce computation, ensuring reliability for larger numbers.

Nested loops effectively control row and column printing. For a triangle, the row number determines star count, and for a pyramid, additional loops manage spaces around stars. Patterns like mirrored or inverse pyramids adjust space and character logic accordingly, requiring adept loop modulation.

Implement input validation checks before processing, using conditional logic to reject out-of-range or illegal inputs. For instance, test operator validity against known operations and score widths against valid intervals, providing corrective prompts or fallback logic like re-entry requests or graceful degradation.

Employ iterative loops like for or while to accumulate products over each term's calculated result. Strategies for large sum/product handling include modular arithmetic to prevent integer overflow, careful loop termination checks, and possibly multi-threading for performance.

The program should first ensure the input scores fall within valid ranges: 0-40 for the midterm and 0-60 for the final. It calculates the total score to map it to a grade using predefined thresholds (e.g., >90 for A, 70-90 for B). If inputs are invalid, it prompts for correct values instead of proceeding.

C++ offers for loops for known iteration counts, while loops for conditional repetition, and do-while loops for at least one execution. Each loop can compute sequences like arithmetic series or factorial products. Selection depends on the problem's specific flow control needs and input characteristics.

A C++ program can use the pow function from the cmath library to compute powers. The program should prompt the user for an integer input n, and then calculate 2^n using pow(2, n). It should handle input validation to ensure n is a reasonable integer.

The algorithm iteratively calculates factorial values for numbers 1 to n and accumulates their sums. Use loops to calculate each factorial, tracking results to avoid recomputation in subsequent iterations. This requires efficient loop control and memory management to handle large integers.

Essential features include parsing input to identify operands and operator, executing operations conditionally, exception handling for illegal operations (e.g., division by zero), and intuitive error messaging. User input validation and operation results display are fundamental to usability.

Use the Sieve of Eratosthenes, marking multiples of each prime starting from the smallest prime (2). This algorithmically eliminates non-prime numbers from the candidate list between 1 and 100, significantly optimizing over iterative primality checks.

You might also like