Categories
C++

Generics in C++

A sample program was written by my friend Tom to demonstrate generics concepts in C++. Thank you for sharing your code Tom.

I am currently accepting programming work inventory system, enrollment system, accounting system, payroll system, information system, website design and development using WordPress, IT projects, school and application development, programming projects, thesis, and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in 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 the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.My mobile number here in the Philippines is 09173084360. My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.


Here in Bacolod City, Negros Occidental I also accepting computer repair, web development using WordPress, Computer Networking, and Arduino Project development at a very affordable price. My personal website is http://www.jakerpomperada.comMy programming website is http://www.jakerpomperada.blogspot.comI am also a book author you can purchase my books on computer programming and information technology in the following links below.https://www.unlimitedbooksph.com/


Program Listing

#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

template<class ReturnType, class Iter>
ReturnType average(Iter first, Iter last)
{
   ReturnType sum = ReturnType();
   size_t count = 0;

   while (first != last)
   {
     ++count;
     sum += *first;
     ++first;
   }
   return sum / count;
}

int main()
{
   vector<int> numbers = { 3, 5, 2, 4, 7, 2, 2 };
   float avg1 = average<float>(numbers.begin(), numbers.end());
   cout << setprecision(10) << "Avg<float> = " << avg1 << '\n';

   double avg2 = average<double>(numbers.begin(), numbers.end());
   cout << setprecision(10) << "Avg2<double> = " << avg2 << '\n';

   long double avg3 = average<long double>(numbers.begin(), numbers.end());
   cout << setprecision(10) << "Avg3<long double> = " << avg3 << '\n';
}
Categories
C++

Student Grade Solver Using Pointers in C++

I wrote this program to compute the student grades using pointers in C++ programming language.

 I am currently accepting programming work inventory system, enrollment system, accounting system, payroll system, information system, website design and development using WordPress, IT projects, school and application development, programming projects, thesis, and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in 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 the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.My mobile number here in the Philippines is 09173084360. My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.


Here in Bacolod City, Negros Occidental I also accepting computer repair, web development using WordPress, Computer Networking, and Arduino Project development at a very affordable price. My personal website is http://www.jakerpomperada.comMy programming website is http://www.jakerpomperada.blogspot.comI am also a book author you can purchase my books on computer programming and information technology in the following links below. https://www.unlimitedbooksph.com/

Program Listing


#include <iostream>
#include <iomanip>

 using namespace std;

float X_Prelim=0.00, X_Midterm=0.00, X_Endterm=0.00;

 float solve_grade(float *prelim,  float *midterm, float *endterm)
 {
     float compute_grade =0.00;
     bool  result;
     compute_grade = (*prelim * 0.30) + (*midterm * 0.30)
                     + (*endterm * 0.40);

    if (compute_grade >= 75.00) {
        result = true;
    }
    else {
        result = false;
    }

    switch(result) {

     case   true : cout << "\nThe Student Passed the Subject.";
                   break;
      case   false : cout << "\nThe Student Failed the Subject.";
                     break;
      default      : cout << "Sorry Invalid Grade !!!";
    }
     return(compute_grade);
 }

 void start()
 {

     cout << "\t\t GRADE SOLVER VERSION 1.0 USING POINTERS";
     cout << "\n\n\t       Created By: Mr. Jake R. Pomperada, MAED-IT";
     cout << "\n\n";
     cout << "Enter Prelim Grade  ==> ";
     cin >> X_Prelim;
     cout << "Enter Midterm Grade ==> ";
     cin >> X_Midterm;
     cout << "Enter Endterm Grade ==> ";
     cin >> X_Endterm;
     cout << "\n";
     cout << fixed;
     cout << setprecision(2);
     cout << "\nYour Final Grade is " <<
          solve_grade(&X_Prelim,&X_Midterm,&X_Endterm) << ".";

     cout << "\n\n";
     system("PAUSE");
 }

main() {

    start();
}

Categories
C++

Swap Two Numbers Using Pointers in C++

I wrote this program to ask the user to give two numbers and then it will swap the arrangement of the two numbers using pointers in C++ programming language.

 I am currently accepting programming work inventory system, enrollment system, accounting system, payroll system, information system, website design and development using WordPress, IT projects, school and application development, programming projects, thesis, and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in 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 the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.My mobile number here in the Philippines is 09173084360. My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.


Here in Bacolod City, Negros Occidental I also accepting computer repair, web development using WordPress, Computer Networking, and Arduino Project development at a very affordable price. My personal website is http://www.jakerpomperada.comMy programming website is http://www.jakerpomperada.blogspot.comI am also a book author you can purchase my books on computer programming and information technology in the following links below.https://www.unlimitedbooksph.com/

Program Listing

#include <iostream>
#include <string>

 using namespace std;

 int swap_value(int *a, int *b, int temp)
 {
  temp = *a;
  *a = *b;
  *b = temp;
 }

 main() {

     int a=0,b=0,temp=0;
      char reply = 'Y';

 for (; toupper(reply)== 'Y'; ) {

 cout << "\n\n";
 cout << "\t\t SWAP A NUMBER USING POINTERS";
 cout << "\n\n\t Created By: Mr. Jake R. Pomperada,MAED-IT";
 cout << "\n\n";
 cout << "Enter the first value  :=> ";
 cin >> a;
 cout << "Enter the second value :=> ";
 cin >> b;

 cout << "\nOrignal value of a : " << a <<".";
 cout << "\nOrignal value of b : " << b <<".";

 cout << "\n\n";

 swap_value(&a,&b,temp);
 cout << "After calling the function Reference/Pointer";
 cout << "\n\n";

 cout << "\nNew value of a : " << a <<".";
 cout << "\nNew value of b : " << b <<".";
 cout << "\n\n";
 cout << "Do You Want To Continue Y/N :=> ";
 cin >> reply;

 }
 if (toupper(reply) == 'N') {
     cout << "\nThank You For Using This Program.";

  }
 cout << "\n\n";
 system("PAUSE");
 }
Categories
C++

Asynchronous file reading in C++

A program written by my friend Tom to demonstrate multi treading concept of programming in C++. Thank you Tom for sharing your code to us.

I am currently accepting programming work inventory system, enrollment system, accounting system, payroll system, information system, website design and development using WordPress, IT projects, school and application development, programming projects, thesis, and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in 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 the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.My mobile number here in the Philippines is 09173084360. My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.


Here in Bacolod City, Negros Occidental I also accepting computer repair, web development using WordPress, Computer Networking, and Arduino Project development at a very affordable price. My personal website is http://www.jakerpomperada.comMy programming website is http://www.jakerpomperada.blogspot.comI am also a book author you can purchase my books on computer programming and information technology in the following links below.https://www.unlimitedbooksph.com/

Program Listing

#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <thread>
#include <future>
#include <chrono>

const std::string lorem = R"(
Lorem ipsum dolor sit amet, consetetur sadipscing
elitr, sed diam nonumy eirmod tempor invidunt ut
labore et dolore magna aliquyam erat, sed diam
voluptua. At vero eos et accusam et justo duo
dolores et ea rebum.
)";

void create_file(std::ostream& os, const std::string& s, int count)
{
   for (int i = 0; i < count; ++i)
     os << s << '\n';
}

std::string read_file(std::istream& is)
{
   std::stringstream ss;
   std::string line;
   int count = 0;

   while(std::getline(is, line))
   {
     ss << line << '\n';
     ++count;
     if (count % 5000 == 0)
     {
       std::cout << "\nThread " << std::this_thread::get_id() << " read
" <<
       count << " lines\n";
       std::this_thread::sleep_for(std::chrono::milliseconds(500));
     }
   }
   return ss.str();
}


int main()
{
   std::cout << "Main thread " << std::this_thread::get_id() << "
started\n\n";
   std::ofstream dest("lorem.txt");
   if (!dest)
   {
     perror("Error creating file. ");
     return EXIT_FAILURE;
   }
   create_file(dest, lorem, 10000);
   dest.close();

   std::ifstream src("lorem.txt");
   if (!src)
   {
     perror("Error opening file. ");
     return EXIT_FAILURE;
   }
   std::future<std::string> content = std::async(std::launch::async,
                                      [&] {return
read_file(std::ref(src));});
   for (int i = 0; i <= 100; ++i)
   {
     if (i % 10 == 0)
     {
       std::cout << "Thread: # " << std::this_thread::get_id()
                 << " i = " << i << '\n';
     }
     // sim long task
     std::this_thread::sleep_for(std::chrono::milliseconds(75));
   }
   std::string str = content.get();
   std::cout << "Length of file: " << str.size() << '\n';
}
Categories
C++

Real Fancy in C++

A program was written by my friend Thomas to test real fancy in C++. Thank you Thomas for sharing your code to us.


I am currently accepting programming work inventory system, enrollment system, accounting system, payroll system, information system, website design and development using WordPress, IT projects, school and application development, programming projects, thesis, and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in 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 the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.My mobile number here in the Philippines is 09173084360. My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.


Here in Bacolod City, Negros Occidental I also accepting computer repair, web development using WordPress, Computer Networking, and Arduino Project development at a very affordable price. My personal website is http://www.jakerpomperada.com


My programming website is http://www.jakerpomperada.blogspot.comI am also a book author you can purchase my books on computer programming and information technology in the following links below.https://www.unlimitedbooksph.com/


Program Listing

/*
Chef was reading some quotes by great people.
Now, he is interested in classifying all the fancy quotes
he knows. He thinks that all fancy quotes which contain
the word "not" are Real Fancy;
quotes that do not contain it are regularly fancy.
You are given some quotes.
For each quote, you need to tell Chef if it is Real Fancy
or just regularly fancy.

https://www.codechef.com/problems/FANCY
*/

#include <iostream>
#include <string>
#include <cstdio>
#include <sstream>

const std::size_t MAX_INPUT_LENGTH = 100;

inline void do_test()
{
  std::string input;
  input.reserve(MAX_INPUT_LENGTH);
  std::getline(std::cin, input);
  std::istringstream iss(input);
  std::string token;
  while (iss >> token)
  {
    if (token == "not")
    {
      std::cout << "Real Fancy\n";
      return;
    }
  }

  std::cout << "regularly fancy\n";
}

int main()
{
  int num_tests;

#ifdef ONLINE_JUDGE
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
#else
  std::freopen("input.txt", "r", stdin);
#endif

  std::cin >> num_tests;
  std::cin.ignore(255, '\n');

  for (int n = 0; n < num_tests; n++)
  {
    do_test();
  }
}
Categories
C++

Temperature Checker in C++

A simple program that I wrote using C++ to ask the user to give a temperature and then the program will check the type of temperature based on the given value of the user using if-else if statement.

I am currently accepting programming work inventory system, enrollment system, accounting system, payroll system, information system, website design and development using WordPress, IT projects, school and application development, programming projects, thesis, and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in 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 the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.My mobile number here in the Philippines is 09173084360. My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.

Here in Bacolod City, Negros Occidental I also accepting computer repair, web development using WordPress, Computer Networking, and Arduino Project development at a very affordable price. My personal website is http://www.jakerpomperada.com

My programming website is http://www.jakerpomperada.blogspot.comI am also a book author you can purchase my books on computer programming and information technology in the following links below.https://www.unlimitedbooksph.com/

Program Listing

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

using namespace std;

int main()
{
    int temp;
    cout << "Enter temperature: ";
    cin >> temp;
    if((temp>=31)&&(temp<=50))
        cout << "VERY HOT";
    else if((temp>=21)&&(temp<=30))
        cout << "WARM";
    else if((temp>=11)&&(temp<=20))
        cout << "VERY COLD";
    else if((temp>=0)&&(temp<=10))
        cout << "FREEZING";
    getch();
    return 0;
}    
        
    
    
Categories
C++

Area of the Triangle in C++

A simple program that I wrote that will ask the user to give base and height value to compute the are of the triangle using C++ programming language.

I am currently accepting programming work inventory system, enrollment system, accounting system, payroll system, information system, website design and development using WordPress, IT projects, school and application development, programming projects, thesis, and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in 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 the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.My mobile number here in the Philippines is 09173084360. My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.

Here in Bacolod City, Negros Occidental I also accepting computer repair, web development using WordPress, Computer Networking, and Arduino Project development at a very affordable price. My personal website is http://www.jakerpomperada.com

My programming website is http://www.jakerpomperada.blogspot.comI am also a book author you can purchase my books on computer programming and information technology in the following links below.https://www.unlimitedbooksph.com/

Program Listing

#include<iostream>
#include<cstdlib>

using namespace std;

int main()
{
    double b,h;

    cout<<"Area of a Triangle Solver"<<endl;
    cout<<"base  : "; 
	cin>>b;
    cout<<"height: "; 
	cin>>h;
    cout<<"area = "
        <<(b*h)/2
        <<" square units "
        <<endl;

    system("pause");
	return 0;
}
Categories
C++

Linear Search Using Modern C++

A linear search program was written by my friend Tom that uses modern C++ approach.


I am currently accepting programming work inventory system, enrollment system, accounting system, payroll system, information system, website design and development using WordPress, IT projects, school and application development, programming projects, thesis, and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in 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 the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.My mobile number here in the Philippines is 09173084360. My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.

Here in Bacolod City, Negros Occidental I also accepting computer repair, web development using WordPress, Computer Networking, and Arduino Project development at a very affordable price. My personal website is http://www.jakerpomperada.com

My programming website is http://www.jakerpomperada.blogspot.comI am also a book author you can purchase my books on computer programming and information technology in the following links below. https://www.unlimitedbooksph.com/


Program Listing

/*
The program will ask the use to give for example five numbers
and then the program will  ask the user what number to search
and the program will find the number and what position the number
is Located in.
*/

#include <iostream>
#include <vector>
#include <algorithm>

constexpr int N = 5;

int main()
{
   std::vector<int> numbers(N);
   int num_to_search;

   for (int i = 0; i < N; ++i)
   {
     std::cout << "Enter number #" << i + 1 << ": ";
     std::cin >> numbers[i];
     std::cout << '\n';
   }
   std::cout << "Enter a number to search for: ";
   std::cin >> num_to_search;

   //http://www.cplusplus.com/reference/algorithm/find/
   auto it = std::find(numbers.begin(), numbers.end(), num_to_search);
   if (it == numbers.end())
   {
     std::cout << "Number not found";
   }
   else
   {
     //http://www.cplusplus.com/reference/iterator/distance/
     std::cout << "Found at pos: " << std::distance(numbers.begin(), it);
   }
}
Categories
C++

Running Sum of Numbers Using Ordinal Indicators in C++

I wrote this simple program to demonstrate how to write a running sum of number using ordinal numbers in C++ programming language.
I am currently accepting programming work inventory system, enrollment system, accounting system, payroll system, information system, website design and development using WordPress, IT projects, school and application development, programming projects, thesis, and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in 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 the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.My mobile number here in the Philippines is 09173084360. My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.


Here in Bacolod City, Negros Occidental I also accepting computer repair, web development using WordPress, Computer Networking, and Arduino Project development at a very affordable price. My personal website is http://www.jakerpomperada.com


My programming website is http://www.jakerpomperada.blogspot.comI am also a book author you can purchase my books on computer programming and information technology in the following links below.https://www.unlimitedbooksph.com/

Sample Program Output

Program Listing
Program Listing
// ordinal.cpp
// Jake Rodriguez Pomperada
// May 26, 2020      Tuesday    10:51 PM

 #include <iostream>
 #include <string>

 using namespace std;
 
string ordinal(int i)
{
	
	
int mod100 = 0, mod10 = 0;

mod100 = (i % 100);
mod10 = (i % 10);
 
if (mod10 == 1 && mod100 != 11) {
return "st";
} else if (mod10 == 2 && mod100 != 12) {
 return "nd";
}
else if (mod10 == 3 && mod100 != 13) {
return "rd";
} else {
return "th";
 }
}

 int main()
 {
 
   int num_items = 0, sum = 0, num;
   
   cout <<"\n\n";
   cout <<"\tRunning Sum of Numbers Using Ordinal Indicators in C++";
   cout <<"\n\n";
   cout << "\tHow many items: ";
   cin >> num_items;
   for (int i = 1; i <= num_items; ++i)
  {
    cout << "\tGive value in the " << i << ordinal(i) << " item: ";
    cin >> num;
    sum += num;
   cout << "\tThe running sum is: " << sum << '\n';
   }
   cout <<"\n";
   cout <<"\tEnd of the Program";
   cout <<"\n";
 }
Categories
C++

Convert Vowels into Upper Case in C++

Here is a program is given to us by my friend Tom. This program asks the user to give a string and then the program will convert all the vowels into upper case format in the given string.


I am currently accepting programming work inventory system, enrollment system, accounting system, payroll system, information system, website design and development using WordPress, IT projects, school and application development, programming projects, thesis, and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in 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 the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.My mobile number here in the Philippines is 09173084360. My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.

Here in Bacolod City, Negros Occidental I also accepting computer repair, web development using WordPress, Computer Networking, and Arduino Project development at a very affordable price. My personal website is http://www.jakerpomperada.com


My programming website is http://www.jakerpomperada.blogspot.comI am also a book author you can purchase my books on computer programming and information technology in the following links below.https://www.unlimitedbooksph.com/

Sample Program Output

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

bool is_vowel(char ch)
{
   const string vowels("aeiouAEIOU");

   return vowels.find(ch) != string::npos;
}

string& vowels_to_upper(string& s)
{
   for (char &ch : s)
     if (is_vowel(ch) && islower(ch))
       ch = toupper(ch);

   return s;
}

int main()
{
   string input;

   cout <<"\n\n";
   cout << "\tConvert Vowels into Upper Case in C++";
   cout <<"\n\n";
   while (true)
   {
     cout << "\tEnter a string (or quit): ";
     getline(cin, input);
     if (input == "quit")
       break;
     cout <<"\t" <<vowels_to_upper(input) << '\n';
    cout <<"\n";
   }
   cout <<"\n";
   cout <<"\tEnd of Program";
   cout <<"\n";
}