C++ Programming Examples: File Handling, Operator Overloading, and More

Write a C++ Program to Write Contents to a File

#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string.h>
using namespace std;
int main()
{
    char fname[20], str[200];
    fstream fp;
    cout << "Enter the Name of File: ";
    gets(fname);
    fp.open(fname, fstream::out);
    if(!fp)
    {
        cout << "\nError Occurred!";
        return 0;
    }
    cout << "Enter the Data: ";
    gets(str);
    while(strlen(str) > 0)
    {
Read More

Understanding Web Development: From Static Pages to Dynamic Applications

Static vs. Dynamic Web Pages

A static web page is delivered and stored as web content.

A dynamic web page is generated by a web application on the server, using user input to the server.

Dynamic behavior is provided using JavaScript code embedded in the HTML of a web page or as separate linked files specified in the HTML.

HTML: The Foundation of Web Pages

An HTML document is a text file that tells a web browser how to assemble a web page.

  • HTML (Hypertext Markup Language) is the markup language for creating
Read More

Software Engineering Principles and Practices

1. Software Engineering Fundamentals

1.1 Orientation & Requirements

Software Engineering refers to the tools and processes we use to design, construct, and maintain programs over time. It encompasses the entire software development life cycle:

Write/Refine Requirements → Create Tests → Design → Code → Debug or Redesign until Tests Past → Deploy/Collect feedback

1.2 Requirements Analysis

This phase focuses on making sure we are building the right thing. There are three major dimensions of

Read More

C Programming Basics: Structures, Pointers, Files, and Multi-dimensional Arrays

What is the Basic Structure of a C Program?

Explanation of Each Part

The basic structure of a C program consists of:

  1. Preprocessor Directives: These include #include statements to include header files, such as <stdio.h> for input and output operations.
  2. Main Function: Every C program must have a main() function, which serves as the entry point of the program.
  3. Declaration Section: This section declares any global variables or functions that will be used throughout the program.
  4. Executable Statements:
Read More

SQL Queries and Database Schema Examples

Q5 (WorldDB): Return the number of cities that are in Australian territories (i.e., cities
in countries where the form of government is ‘Territory of Australia’). 
select count(*)
from city
where city.countrycode  in
(select code
from country
where governmentform='Territory of Australia');

Q6 (WorldDB): Return the number of countries in South America that have no official
languages. 
select count(*) from(
select name, count(isofficial) 
from country left outer join countrylanguage
on code=countrycode

Read More

Data Structures and Algorithms: A Comprehensive Guide

Heap

A heap is a complete binary tree in which the value of each node is greater than or equal to the values of its children (if any) (a maxheap). Dequeuing the object with the greatest value appears to be a (1) operation. It only takes O(lgn) time to turn the structure back into a heap again. The process of swapping downwards to form a new heap is called heapifying. Enqueue uses a loop (a loop is used for heapifying ), and it is a O(lgn) operation (swapping in reverse) (O( lg n ) complexity). Each

Read More