Posts

Simple C++ Functions to Calculate Area of Square and Volume of Cuboid

This is the simple C++ program to calculate area and volume. #include <iostream> using namespace std ; int a_square ( int length) { return length*length ; } int v_cuboid ( int length , int height) { return a_square(length)*height ; //return length*length *height; } void volume_cuboid () { int length , height ; cout << "Enter the length of the cuboid: " ; cin >> length ; cout << "Enter the height of the cuboid: " ; cin >> height ; cout << "The volume of the cuboid is " << v_cuboid(length , height) ; } void area_square () { int length ; cout << "Enter the length of the square: " ; cin >> length ; cout << "The area of th square is " << a_square(length) << endl ; } int main () { area_square() ; //functions declared volume_cuboid() ; }

What is LDR and how it works with circuit to try on?

Image
  LDR ( Light-dependent resistor) A photo-resistor (or light-dependent resistor, LDR, or photo-conductive cell) is a light-controlled variable resistor. The resistance of a photo-resistor decreases with increasing incident light intensity; in other words, it exhibits photoconductivity. [1] In the dark, their resistance is very high, sometimes up to 1MΩ, but when the LDR the sensor is exposed to light, the resistance drops dramatically, even down to a few ohms, depending on the light intensity. LDRs have a sensitivity that varies with the wavelength of the light applied and are nonlinear devices. For example it can be used to turn on a light when the LDR is in darkness or to turn o­ a light when the LDR is in light. It can also work the other way around so when the LDR is in the light it turns on the circuit and when it’s in darkness the resistance increases and disrupts the circuit. How it Works? The way an LDR works is that they are made of many semi-conductive mate...

Encrypted secrete messages in C++

How to send Encrypted secrete messages in C++ and Decrypt the same message? #include <iostream> #include<string> using namespace std ; int main() {     string message;     int i,a,word;     string letters ={ "ABCDEFGHIKLMNOPQRSTVXYZabcdefghijklmnopqrstuvwxyz" };     string key=     { "sub£rmatoglyphicAXPYRIQW\CMSWBFG@1029384756!&()=" };     cout << "Enter the message: " ;     getline( cin ,message);     string encrypted_message;     string decrypted;     for ( char c:message){     size_t position=letters.find(c);     if (position !=string::npos)     {     char new_char = key.at(position);     encrypted_message+=new_char;     }     else     {     encrypted_message+=c;     }     for ( char c:key)     size_t position=key.find(c); ...

Palindrome in C++

This program tells weather the word is palindrome or not and reverses the word given by the user with a number of letters. #include <iostream> #include <cstring> ##To use string library using namespace std; int main() {     string word;         int i;         int points=0;         cout << "Enter the palindrome word(small letter) you want check: ";         getline(cin, word); #Taking the input from the user         int a = word.length(); ##Counting numbers of words and storing in integer a         cout << "The word is " << a << " letters long." << endl;         cout << "The reverse word is ";         {...

Adding two Matrix (3 x 3) In C programming

The files "mata.txt" and "matb.txt" contain integer matrices of size 3 x 3. Write a program that calculates the sum of the matrices in a new matrix. The resulting sum matrix shall be saved to the file "sum.txt". #include<stdio.h> int main() {     FILE *filea, *fileb,*filec; //initialize the files     int arraya[3][3],arrayb[3][3],sum[3][3]; //initialize arrays which consists 3*3 elements       int i ,j; //PART A //We try to read from file mata.txt (filea).     if ((filea=fopen("mata.txt","r"))==NULL) // try to read from txt file      {         printf("Failed to open mata.txt");      }     else     {         for(i=0;i<3;i++)         {             for(j=0;j<3;j++){                 fscanf(filea,"%d",&arraya[i][j]); //reading f...

2D Array Explained Using Matrix

Image
2D Array Explained Let's create an array that has 2 dimensions like a matrix. Now let's give it some elements. Let's say int matrix[5][5] =  { 4, 6, 25, 88, 5, 34, 5, 300, 4, 65, 78, 43, 11, 90, 125, 98, 585, 12, 63, 21, 45, 35, 9, 5, 1 }; Now, we will see how to access the elements in the array. To do that we need to use nested for loop. Let's initialize two values i and j.  So, int i,j;    // Here i represents row and j represents column. That means when i=0 and j=0, it gets the first element from the matrix i.e 4 and when i=0 and j=1 it gets second element 6 and so on...  Now let's write whole C code to access the elements inside the array matrix. #include<stdio.h> int main() {     int i,j,sum;     int array[5][5]={             4, 6, 25, 88, 5,             34, 5, 300, 4, 65,          ...

Use of Array

Use of a 1D array Write a program that calculates the number of hours worked within a specific period and prints the total number of hours, the average length of a day and an itemization of the hours entered. First, the program must ask how many days of working hours shall be entered (max 30 days). After this, the program asks for the daily working hours. The program output shall have one decimal place of precision. #include <stdio.h> int main() {     printf("The program calculates the total hours worked during\na specific period and the average length of a day.\n");     int days,i;     float array[30],sum; //initilize array which can store 30 values or 120 bytes (4*30)     printf("How many days:");     scanf("%d",&days);     for (i=0; i<days; ++i)     {        printf("Enter the working hours for day %d:",i+1);        scanf("%f",& array[i]...