0% found this document useful (0 votes)
2 views6 pages

C++ Programing

The document provides a series of C++ and web technology programs, specifically tailored for Turbo C++ and HTML. It includes examples of basic C++ constructs such as classes, constructors, destructors, inheritance, and file handling, as well as HTML examples demonstrating physical tags, image mapping, forms, CSS, and JavaScript. The document concludes with an offer to provide a ZIP file of all the examples or combine them into a project.

Uploaded by

xrxeal
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)
2 views6 pages

C++ Programing

The document provides a series of C++ and web technology programs, specifically tailored for Turbo C++ and HTML. It includes examples of basic C++ constructs such as classes, constructors, destructors, inheritance, and file handling, as well as HTML examples demonstrating physical tags, image mapping, forms, CSS, and JavaScript. The document concludes with an offer to provide a ZIP file of all the examples or combine them into a project.

Uploaded by

xrxeal
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
You are on page 1/ 6

C++ Program as per the turbo C++

• #include <iostream.h> instead of #include <iostream>


• void main() instead of int main()
• Use clrscr() and getch() from conio.h for screen handling

1. Simple Program in Turbo C++


#include <iostream.h>
#include <conio.h>

void main() {
clrscr();
cout << "Hello, World!";
getch();
}

2. Class and Object


#include <iostream.h>
#include <conio.h>

class Car {
public:
void display() {
cout << "This is a car.";
}
};

void main() {
clrscr();
Car myCar;
myCar.display();
getch();
}

3. Constructor
#include <iostream.h>
#include <conio.h>

class Person {
public:
Person() {
cout << "Constructor called!" << endl;
}
};

void main() {
clrscr();
Person p1;
getch();
}

4. Destructor
#include <iostream.h>
#include <conio.h>

class Person {
public:
Person() {
cout << "Constructor called!" << endl;
}
~Person() {
cout << "Destructor called!" << endl;
}
};

void main() {
clrscr();
Person p1;
getch();
}

5. Single Inheritance
#include <iostream.h>
#include <conio.h>

class Animal {
public:
void eat() {
cout << "Eating..." << endl;
}
};

class Dog : public Animal {


public:
void bark() {
cout << "Barking..." << endl;
}
};

void main() {
clrscr();
Dog d;
d.eat();
d.bark();
getch();
}

6. Mutator Method (Setter)


#include <iostream.h>
#include <conio.h>

class Student {
private:
int age;

public:
void setAge(int a) {
age = a;
}

int getAge() {
return age;
}
};

void main() {
clrscr();
Student s;
s.setAge(20);
cout << "Student age is: " << s.getAge();
getch();
}

7. File Handling
#include <fstream.h>
#include <iostream.h>
#include <conio.h>

void main() {
clrscr();
ofstream outFile("sample.txt");
outFile << "This is a sample text file.\n";
outFile.close();

ifstream inFile("sample.txt");
char ch;
while (inFile.get(ch)) {
cout << ch;
}
inFile.close();
getch();
}

Web Technology
1. HTML Program with Fundamental/Physical Tags
<!DOCTYPE html>
<html>
<head>
<title>Physical Tags</title>
</head>
<body>
<b>This is bold text</b><br>
<i>This is italic text</i><br>
<u>This is underlined text</u><br>
<strike>This is strikethrough text</strike><br>
<small>This is small text</small><br>
<big>This is big text</big>
</body>
</html>

2. Program of Image Mapping


<!DOCTYPE html>
<html>
<head>
<title>Image Map</title>
</head>
<body>
<img src="image.jpg" usemap="#map" width="500" height="300">
<map name="map">
<area shape="rect" coords="0,0,100,100" href="https://www.google.com"
alt="Google">
<area shape="circle" coords="200,150,50" href="https://www.youtube.com"
alt="YouTube">
</map>
</body>
</html>

Replace "image.jpg" with your image file.

3. Program of HTML Form Tag


<!DOCTYPE html>
<html>
<head>
<title>Form Example</title>
</head>
<body>
<form action="submit.php" method="post">
Name: <input type="text" name="name"><br>
Email: <input type="email" name="email"><br>
Password: <input type="password" name="pass"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

4. Program of Internal CSS


<!DOCTYPE html>
<html>
<head>
<title>Internal CSS</title>
<style>
body {
background-color: lightblue;
}
h1 {
color: darkblue;
}
p {
font-size: 18px;
}
</style>
</head>
<body>
<h1>Welcome</h1>
<p>This page uses internal CSS.</p>
</body>
</html>

5. Program of External CSS

1. HTML file: index.html

<!DOCTYPE html>
<html>
<head>
<title>External CSS</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>Hello!</h1>
<p>This uses external CSS.</p>
</body>
</html>

2. CSS file: style.css

body {
background-color: lightgreen;
}

h1 {
color: darkgreen;
}

p {
font-family: Arial;
}

6. Simple Program of JavaScript


<!DOCTYPE html>
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<h1>Click the button</h1>
<button onclick="sayHello()">Click Me</button>

<script>
function sayHello() {
alert("Hello from JavaScript!");
}
</script>
</body>
</html>

7. JavaScript Program for For Loop and While Loop


<!DOCTYPE html>
<html>
<head>
<title>Loops in JavaScript</title>
</head>
<body>
<script>
document.write("<h3>For Loop:</h3>");
for (let i = 1; i <= 5; i++) {
document.write("Number: " + i + "<br>");
}

document.write("<h3>While Loop:</h3>");
let j = 1;
while (j <= 5) {
document.write("Number: " + j + "<br>");
j++;
}
</script>
</body>
</html>

8. PHP Program for For and While Loop


<!DOCTYPE html>
<html>
<head>
<title>Loops in PHP</title>
</head>
<body>
<?php
echo "<h3>For Loop:</h3>";
for ($i = 1; $i <= 5; $i++) {
echo "Number: $i<br>";
}

echo "<h3>While Loop:</h3>";


$j = 1;
while ($j <= 5) {
echo "Number: $j<br>";
$j++;
}
?>
</body>
</html>

Let me know if you'd like a ZIP file of all these or want them combined into a project!

You might also like