Programming Fundamentals Whole
Programming Fundamentals Whole
In equation :
Pre increment : first increament in value ) use
Post increment : first use ) increment
Bool flag:
Possible states two , 0 or 1, on or off, true or false
#include<iostream> # all the lines starting with # symbols are the preprocessed code in c++
#include<iomanip>
#include<string>
using namespace Include is the name of directive which will add,embed,include.the
int main() content of prewritten header file specified in the next
{
Int number;
Char grade=’A’; iostream is the built in code from the c++ to input and output
cout<<”enter valid number”; data on console (CMD or DOS) or (it’s a path or pipe code and
cin>>number; code
cout<<”sizeof(int)”; iomanip is also built in code from the c++ to format or
y=++number; manipulate the data
string is built in code for string data input .
return 0;
} Cin/cout are input/output object. Console input/output
screen.
<< insertion operator >>exertion operator
; represent the end of line and it is necessary .
{} necessary for body
0: successful 1: unsuccessful
Evaluate expression z = (x + y) / 7
INPUT x, y
z = (x + y) / 7
PRINT z
Evaluate expression (3x + y) / (z + 2)
INPUT x, y, z
PRINT (3 * x + y) / (z + 2)
Evaluate expression (3x + z) / (y + 12)
INPUT x, y, z
PRINT (3 * x + z) / (y + 12)
Calculate and display Area of Rectangle
INPUT length, width
area = length * width
PRINT area
Input two variables, store sum in first and difference in second
INPUT num1, num2
num1 = num1 + num2
num2 = num1 - num2
PRINT num1, num2
Selection;
Solved selection pdf
1. High or Low Score:
One-Way If Statements:
1. Absolute Value:
INPUT number
if ( number < 0 )
OUTPUT "Absolute value: ":
else
OUTPUT "Absolute value: "
end if
2. Number of Days in a Month
INPUT month
if (month = 1 OR month = 3 OR month = 5 OR month = 7 OR month = 8 OR month = 10 OR month = 12
)
OUTPUT "31 days"
elseif( month = 4 OR month = 6 OR month = 9 OR month = 11 )
OUTPUT "30 days"
else // February is not handled accurately here - Needs correction for leap year
OUTPUT "28 days"
end if
3. Single Digit to String:
INPUT digit
if (digit = 0 )
OUTPUT "zero"
elseif( (digit = 1 )
OUTPUT "one"
elseif( (digit = 2 )
OUTPUT "two" etc
end if
4. Point Location
INPUT x, y
if( x > 0 AND y > 0 )
OUTPUT "Point lies in First Quadrant"
elseif(( x < 0 AND y > 0 )
OUTPUT "Point lies in Second Quadrant"
elseif(( x < 0 AND y < 0 )
OUTPUT "Point lies in Third Quadrant"
elseif( (x > 0 AND y < 00)
OUTPUT "Point lies in Fourth Quadrant"
else
OUTPUT "Point lies on the origin"
end if
Conditional
1. In Range:
INPUT number
if (number >= 1 AND number <= 100 )
OUTPUT "In Range"
else
OUTPUT "Out of Range"
end if
2. Number of Digits:
INPUT number
if( number < 0 )
OUTPUT "Invalid Input: Enter a positive number"
elseif( (number < 10 )
OUTPUT "One digit"
elseif(( number < 100 )
OUTPUT "Two digits"
else
OUTPUT "Three digits"
end if
3. Temperature and Pressure Warning:
INPUT temperature, pressure
if( temperature >= 100 OR pressure >= 200)
OUTPUT "Warning"
else
OUTPUT "OK"
end if
4. Marks Grading:
INPUT marks
if( marks > 85)
OUTPUT "Excellent"
elseif( (marks >= 80 )
OUTPUT "Very Good"
elseif( (marks >= 75 )
OUTPUT "Good"
elseif( (marks >= 65 )
OUTPUT "Fair - You may not get the degree with such marks"
else
OUTPUT "Fail"
end if
Repetition;
Solved repetition pdf
Finding the sum of 10 numbers taken from the user:
sum = 0
count = 0
while count < 10:
num = ("Enter a number: ")
sum = sum + num
count = count + 1
print("Sum of 10 numbers is:", sum)
Finding the sum of n numbers taken from the user, where n is taken from the user as well
sum = 0
n = ("Enter the number of elements: ")
count = 0
while (count < n)
num = input number
sum = sum + num
count = count + 1
print("Sum of", n, "numbers is:", sum)
Calculate the factorial of a positive integer entered by the user:
factorial = 1
num = Enter a positive integer
while ( num > 0)
factorial = factorial * num
num = num - 1
print("Factorial is:", factorial)
Take two positive integers a and n from the user. Calculate and display a^n. Assume that
the power operator is not available.
result = 1
a = Enter a
n = Enter n
count = 0
while (count < n)
result = result * a
count = count + 1
print(a, "raised to the power", n, "is:", result)
Take three numbers from the user and determine the largest number. Do it using a loop.
Input max_num
count = 0
while (count < 3)
num = Enter a number
if (num > max_num)
max_num = num
count = count + 1
print("Largest number is:", max_num)
Take a positive integer from the user. Keep displaying an error message and prompting for
input again and again if the user enters invalid input (negative or zero).