Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

‫پوهنتون کاردان‬

Kardan University
Assignment No.01
Course Title: Programming Language Last Date: 05-11-2020
Concepts
Instructor: Amjad Khan Program: BCS
Student Name: Wahida Rashid Semester: Fall-2020
Reg No: 201-2009016 Total Marks = 05
Note: Attempt all of the following questions.
Q1. Five alphabets a,e,i,o and u are known as vowels. All other alphabets
except these five are known as consonants. Write down a computer program
in C++ that accept a single character (uppercase or lower case) as input
from keyboard at runtime and accurately predict that you entered vowel
or consonant.
Ans1:
#include <iostream.h>
#include<conio.h>
Void main (void)
{
Textbackground(8);
Textcolor(7);
Clrscr();
char x = 'a';
cout<<” enter any value for x=”;
cin>>x;
if (x == 'a' || x == 'e' || x == 'i' ||

x == 'o' || x == 'u' || x == 'A' ||

x == 'E' || x == 'I' || x == 'O' || x == 'U')


{
Gotoxy(10,10);
cout << "you entered Vowel"<<x;

}
else
{

Gotoxy(10,10);
cout <<"you entered Consonant"<<x;
}

getch();
}

Q2. Write down a computer program in C++ to enter three integer numbers from
the keyboard at runtime and the program calculate that which number is
greater with a proper message.
Ans2:
#include <iostream.h>
#include<conio.h>
Void main (void)
{
Textbackground(7);
Textcolor(8);
Clrscr();
Int x.y,z;
Cout<<” enter any number for x=”;
Cin>>x;
Cout<<” enter any number for y=”;
Cin>>y;
Cout<<” enter any number for z=”;
Cin>>z;

If((x>y)&&(x>z))
{
Gotoxy(10,10);
Cout<<”x is greatest“<<x;
}
Else
{
If(y>x)&&(y>z))
{
Gotoxy(10,10);
Cout<<”y is greatest”<<y;
}
Else
{
If(z>y)&&(z>x))
{
Gotoxy(10,10);
Cout<<”z is greatest”<<z;
}
Getch();
}
}
}

Q3. All years which are perfectly divisible by 4 are leap years except for
century years (years ending with 00) which is leap year only it is
perfectly divisible by 400.For example: 2012, 2004, 1968 etc are leap
year but, 1971, 2006 etc are not leap year. Similarly, 1200, 1600, 2000,
2400 are leap years but, 1700, 1800, 1900 etc are not. Therefore write a
C++ program to accept a year at runtime and check that the user entered
year is leap year or not?
Ans3:

#include <iostream.h>
#include<conio.h>
Void main (void)
{
Textbackground(7);
Textcolor(8);
Clrscr();
Int year;
Cout<<”Enter any year=”;
Cin>>year;
If((year % 4==0)||(year%400==0))
{
Gotoxy(10,10);
Cout<<”this is leap”<<year;
}
Else
{
Gotoxy(10,10);
Cout<<”Sorry this is not leap”<<year;
}
Getch();
}

Q4. Give detail answer of the following questions with coding example.
a. What is the difference between Declaration and Definition/initialization
of a variable?
Ans a:
Declaration:
Declaration of a variable is for informing to the compiler the following information name of the variable
type of value and declaration gives detail about properties of a variable.
Example :

Int var1;

Definition/Initialization:
To initialize value ,during function.and initialization of a variable provides its initial value at the time of
construction.

Example :

Int var2=10;

b. What is the difference between equal to (==) and assignment (=)


Operators?

Ans b:
Equal to (==):
The ‘==’ operator checks the two given operands are equal or not.

“=”
The ‘=’ is assignment operator is used to assign the value on the right to the variable on the left.

c. What are the various compound assignment operators in C++?

(+=,-=,*=,/=,%=,>=,<=, &=,^=,|=)

1:(+=,-=,*=,/=,%=)
Are the arithmetic operators used for arithmetic operations.

+= used for addition

-= used for substraction

*= used for multiplication

/= used for division

%= used for remainder

2: (>=,<=)
Are known as relational operators.

>= greater than or equal

<= less than or equal


3: (&=,^=,|=)
These are kniown as bitwise operator.

&= AND EQUAL

^= XOR EQUAL

|= OR EQUAL

Q5. Explain the purpose and usage of the following functions in C++
a. textbackground(color)

a)
we can color or change the background and text color in the output screen.

b. textcolor(color)

b)
we can color the text in the output screen.

c. clrscr()

c)
Used to clear the screen and moves cursor to the upper left-hand corner of the screen,and it works only
in turboc++ compiler.

d. getch()

d)
getch (get character) the getch() function in c++ reads the next character from stdin which is usually the
keyboard.

e. getche()

e)
getche ( get character echo) Is a function which waits for any character input from keyboard and it will
also echo the input character on to the output screen.
f. gotoxy(col, row)

f)
gotoxy is buidin function used in cpp language ,we usually use for printing our text or character on the
screen on our desired place it means we can print the character in columns and rows which we want to
display.

You might also like