Learn Computer Programming Free from our source codes in my website.
Sponsored Link Please Support
https://www.techseries.dev/a/27966/qWm8FwLb
https://www.techseries.dev/a/19181/qWm8FwLb
My Personal Website is http://www.jakerpomperada.com
Email me at jakerpomperada@gmail.com and jakerpomperada@yahoo.com
Thursday, April 8, 2021
Saving a Text in a Text File in C++
A simple program that I wrote in C++ to save a text file I hope you will find my work useful.
#include <iostream>
#include <fstream>
using namespace std;
main() {
ofstream myfile("test.txt");
myfile << "Saving a Text in a Text File in C++";
myfile.close();
}
Wednesday, April 7, 2021
Quick Sort in C++
A simple program quick sort in C++ program that I wrote while I am learning C++ programming.
My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com
Program Listing
// quick_sort.cpp
// Prof. Jake R. Pomperada, MAED-IT, MIT
// www.jakerpomperada.com / www.jakerpomperada.blogspot.com
// jakerpomperada@gmail.com
// Bacolod City, Negros Occidental Philippines
#include <iostream>
#include <cstdlib>
using namespace std;
void swap_numbers(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
int Partition(int a[], int low, int high)
{
int pivot, index, i;
index = low;
pivot = high;
for(i=low; i < high; i++)
{
if(a[i] < a[pivot])
{
swap_numbers(&a[i], &a[index]);
index++;
}
}
swap_numbers(&a[pivot], &a[index]);
return index;
}
int RandomPivotPartition(int a[], int low, int high)
{
int pvt, n, temp;
n = rand();
pvt = low + n%(high-low+1);
swap_numbers(&a[high], &a[pvt]);
return Partition(a, low, high);
}
int QuickSort(int a[], int low, int high)
{
int pindex;
if(low < high)
{
pindex = RandomPivotPartition(a, low, high);
QuickSort(a, low, pindex-1);
QuickSort(a, pindex+1, high);
}
return 0;
}
int main()
{
int n=0, i=0;
cout <<"\n";
cout <<"\t\tQuick Sort in C++";
cout <<"\n\n";
cout<<"\tHow many items to be sorted? ";
cin>>n;
int arr[n];
for(i = 0; i < n; i++)
{
cout<<"\tEnter item no. "<<i+1<<": ";
cin>>arr[i];
}
cout <<"\n";
cout<<"\tUnSorted Items\n ";
cout <<"\n";
cout <<"\t";
for (i =0; i < n; i++) {
cout<<" ,"<<arr[i];
}
cout <<"\n";
QuickSort(arr, 0, n-1);
cout <<"\n\n";
cout<<"\tSorted Item \n";
cout <<"\n";
cout <<"\t";
for (i = 0; i < n; i++) {
cout<<" ,"<<arr[i];
}
cout <<"\n\n";
cout <<"\tEnd of Program";
cout <<"\n";
}
Tuesday, April 6, 2021
Asterisk Triangle in Java
A simple program that will ask the user to give a number and then the program will generate the asterisk triangle using Java programming language.
My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com
Program Listing
/* Asterisk.java
* Author : Jake Rodriguez Pomperada, MAED-IT, MIT
* April 5, 2021 8:13 PM
* www.jakerpomperada.blogspot.com
* www.jakerpomperada.com
* jakerpomperada@gmail.com
* Bacolod City, Negros Occidental
*/
import java.util.Scanner;
public class Asterisks {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println();
System.out.print("\tAsterisk Triangle in Java");
System.out.println("\n");
System.out.print("\tEnter a number: ");
int number = scan.nextInt();
int res;
System.out.println("\n");
for (int a=1; a<=number; a++) {
System.out.print("\t");
res = number - a;
for (int b=0; b<=res;b++) {
System.out.print("*");
}
System.out.println("");
}
}
}
Money Denomination Checker in PERL
Machine Problem
Create and design a program that will ask the amount from the user and then our program will count how many one thousand, five hundred, two hundred, one hundred, fifty and twenty bills based here in the Philippine currency.
My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com
Sum and Product of Two Numbers in PERL
Machine Problem
Create and design a program that will ask the user to give two numbers and then the program will compute the sum and product of the given numbers and display the results on the screen.
Monday, April 5, 2021
Decimal To Roman Numeral in C++
A simple program that will ask the user to give a number in decimal and convert it into Roman Numeral Equivalent using C++ programming language.
My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com
Program Listing
// roman.cpp
// Prof. Jake R. Pomperada, MAED-IT,MIT
// www.jakerpomperada.com / www.jakerpomperada.blogspot.com
// jakerpomperada@gmail.com
// Bacolod City, Negros Occidental Philippines
#include <iostream>
#include <string>
using namespace std;
string decimal_to_roman(int x) {
int dec[13] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
string num[13] = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};
string numeral;
for(int i = 0; i < 13; i++) {
while (x >= dec[i]) {
x -= dec[i];
numeral.append(num[i]);
}
}
return numeral;
}
int main() {
int decimal=0;
cout <<"\n\n";
cout <<"\tDecimal To Roman Numeral in C++";
cout <<"\n\n";
cout << "\tGive a Number : ";
cin >> decimal;
cout << "\n";
cout << "\tThe given number is " << decimal;
cout << "\n";
cout << "\tThe Roman Numeral Value is "<< decimal_to_roman(decimal);
cout << "\n\n";
cout <<"\tEnd of Program";
}
Password in C++
My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com
Program Listing
password.cpp
// password.cpp
// Prof. Jake R. Pomperada, MAED-IT,MIT
// www.jakerpomperada.com / www.jakerpomperada.blogspot.com
// jakerpomperada@gmail.com
// Bacolod City, Negros Occidental Philippines
#include <iostream>
#include <string>
using namespace std;
int main()
{
string password = "123";
string passwordEntry;
int attempts = 0;
cout <<"\n\n" ;
cout << "\tPassword in C++\n\n";
cout << "\tPlease enter your password: ";
getline(cin, passwordEntry, '\n');
while ( passwordEntry != password && attempts <=2 )
{
cout << "\n";
cout <<"\tPassword Attempt No. : " <<attempts+1;
cout << "\n";
cout << "\tEnter Password Again : ";
getline(cin, passwordEntry, '\n');
attempts++;
}
if ( passwordEntry == password && attempts <=3 )
{
cout << "\n";
cout << "\tAccess Granted in the System.";
}
else
{
cout << "\n";
cout << "\tSorry, you are only allowed 3 password login attempts.";
cout << "\n\n";
}
}
Saturday, April 3, 2021
Count Number of Words From a Text File in Python
In this program I will show you how to count the number of words from a text file using Python programming language.
I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com
Program Listing
data.txt
Python Programming is Fun and Profit
Professor Jake Rodriguez Pomperada
reading_textfile.py
# reading_textfile.py
# Mr. Jake Rodriguez Pomperada, MAED-IT, MIT
# www.jakerpomperada.com www.jakerpomperada.blogspot.com
# jakerpomperada@gmail.com
# April 3, 2021
# Bacolod City, Negros Occidental
print()
print("\tCount Number of Words From a Text File in Python");
print()
try:
print()
fr = open("data.txt","r")
for line in fr:
line = line.strip("\n")
print(line.upper())
words = line.split()
print()
print('Total number of words: ', len(words))
print("-----------------------------------------------")
print()
print("\tEND OF PROGRAM");
print()
fr.close()
except FileNotFoundError:
print("File is not found")