Nothing Special   »   [go: up one dir, main page]

Doubts

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 11

Set 3

1)

#include <iostream.h>

#include <string.h>

#include<conio.h>

int add(int a, int b) {

return a + b;

char* add(char a[], char b[]) {

strcat(a,b);

return a;

char* add(char b[], int len) {

static char t[20];

int i=0;

while(i<len){

t[i]=b[i];

i++;

t[i]='\0';

return t;
}

int main() {

// Examples of using add function

clrscr();

cout << add(2, 3) << endl; // Output: 5

cout << add("hello", "world") << endl; // Output: helloworld

cout << add("hello", 3) << endl; // Output: hel

getch();

return 0;

3)

#include<graphics.h>

#include<conio.h>

#include<stdio.h>

void main()

int gd = DETECT ,gm, i;

float x, y,dx,dy,steps;

int x0, x1, y0, y1;

initgraph(&gd, &gm, " C:\\Turboc3\\BGI ");

setbkcolor(WHITE);

x0 = 100 , y0 = 200, x1 = 500, y1 = 300;


dx = (float)(x1 - x0);

dy = (float)(y1 - y0);

if(dx>=dy)

steps = dx;

else

steps = dy;

dx = dx/steps;

dy = dy/steps;

x = x0;

y = y0;

i = 1;

while(i<= steps)

putpixel(x, y, RED);

x += dx;

y += dy;

i=i+1;

getch();

closegraph();

}
4)

#include<stdio.h>

#include<graphics.h>

#include<dos.h>

#include<conio.h>

//functionforprinting

//messageascoloredcharacter

void printMsg(char s[])

//autodetection

int gdriver=DETECT,gmode,i;

//initializegraphicsmode

initgraph(&gdriver,&gmode,"C:\\Turboc3\\BGI");

for(i=3;i<15;i++)

//setcolorofcursor

setcolor(i);

//printtextatcoordinatex,y;
outtextxy(20*i,100,s);

delay(500);

cleardevice();

getch();

//driverprogram

int main()

printMsg("eesha");

return 0;

Set 2)

2)

#include<stdio.h>

#include<iostream.h>

#include<conio.h>

//function to check prime number

int isPrimeNumber(int num)

int i = 0,flag = 1;

if(num <= 1)

{
flag = 0;

else

for(i = 2; i <= (num/2); i++)

if((num % i) == 0) // Check prime num

flag = 0;

break;

return flag;

int main()

int num1, num2,i;

clrscr();

cout<<"enter first range";

cin>>num1;

cout<<"enter second range";

cin>>num2;

for(i = num1; i < num2; ++i)

{
if(isPrimeNumber(i) && isPrimeNumber(i+2))

cout<<"{"<<i<<","<<i+2<<"}\n";

getch();

Set1)

4) move horizontally

#include<stdio.h>

#include<graphics.h>

#include<dos.h>

#include<conio.h>

//functionforprinting

//messageascoloredcharacter

void printMsg(char s[])

//autodetection

int gdriver=DETECT,gmode,i;

//initializegraphicsmode

initgraph(&gdriver,&gmode,"C:\\Turboc3\\BGI");
for(i=3;i<15;i++)

//printtextatcoordinatex,y;

outtextxy(20*i,100,s);

delay(500);

cleardevice();

getch();

//driverprogram

int main()

printMsg("eesha");

return 0;

2)

#include<iostream.h>

#include<string.h>
#include<conio.h>

class BankAccount {

private:

char depositorName[10];

int accountNumber;

char accountType[20];

double balance;

public:

BankAccount() { // Default constructor

strcpy(depositorName,"");

accountNumber = 0;

strcpy(accountType,"");

balance = 0.0;

void assignInitialValues(char name[], int number, char type[], double initialBalance) {

strcpy(depositorName,name);

accountNumber=number;

strcpy(accountType,type);

balance = initialBalance;

void deposit(double amount) {


balance += amount;

void withdraw(double amount) {

if (amount <= balance) {

balance -= amount;

} else {

cout <<"Insufficient balance"<< endl;

void display() {

cout <<"Name: "<< depositorName << endl;

cout <<"Account number: "<< accountNumber << endl;

cout <<"Account type: "<< accountType << endl;

cout <<"Balance: "<< balance << endl;

};

void main(){

BankAccount myAccount;

clrscr();

myAccount.assignInitialValues("John Doe", 12345, "Savings", 1000.0);

myAccount.deposit(500.0);

myAccount.withdraw(200.0);
myAccount.display();

getch();

You might also like