Start Learning Oracle

 

C++ Programming by Example: Key computer programming concepts for beginners. Kindle edition
By Sergey Skudaev
http://www.amazon.com/dp/B00EUSMTUW

C++ Programming by Example: Key computer programming concepts for beginners. Paperback
http://www.amazon.com/dp/1983756512

Subscribe to our code examples list

* indicates required
 
 

Video Content

// poet.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include
#include
#include 
#include 
#include 
// Program writes rhymed poem: 4 lines from words chosen randomly

void Initialize(char noun1[][20], char verb1[][20], char adj1[][20]);
char *ReturnThreeFromTheRight(char*string);
int IsRhymes(char *word1, char *word2);
void WritePoem(char noun1[][20], char verb1[][20], char adj1[][20]);

void main()
{
	char noun1[7][20];
	char adj1[7][20];
	char verb1[3][20];



	Initialize(noun1, verb1, adj1);

	WritePoem(noun1, verb1, adj1);

	int hold = 1;
	std::cin >> hold;

}
void Initialize(char noun1[][20], char verb1[][20], char adj1[][20])
{
	char * noun[] = { "switch", "grain", "goat", "witch","deal","food","stool", "toad", "fate", "feet",
		"knish", "meal", "meat","mood", "wolf", "house", "rain", "sleet", "train", "golf",
		"skate", "tool", "wood", "wish", "peat", "mouse", "pitch", "chain", "boat", "squeal",
		"drool", "pool","plate", "beet","catfish", "seat","rolf","grouse","coat","woad","road","food"};

	char *verb[] = { "flew on", "jumped off", "ran over","rolled over","jumped on","crushed","made happy","left with","scared off","wished for","ate","caught","sought for", "twisted", "gulped down", "tricked", "punched", "stuck", "smiled to", "laughed at", "knocked off","broke", "swallowed" };

	char *adj[] = { "great","red", "blue","yellow","gray","funny","smart","silly","brave","dangerous","little","jealous", "strong","pale", "furious", "green", "big", "cool", "greedy", "vicious" };

	int i, k, l, j, n;

	srand(time(0));

	i = rand() % 41;
	strcpy_s(noun1[0], noun[i]);

	i = rand() % 40;
	strcpy_s(noun1[1], noun[i]);

	i = rand() % 39;
	strcpy_s(noun1[3], noun[i]);

	i = rand() % 38;
	strcpy_s(noun1[4], noun[i]);

	for (k = 0; k<42; k++)
	{
		if (IsRhymes(noun1[1], noun[k]))
			strcpy_s(noun1[2], noun[k]);
	}

	if (strcmp(noun1[1], noun1[2]) == 0)
	{
		for (n = 41; n >0; n--)
		{
			if (IsRhymes(noun1[1], noun[n]))
				strcpy_s(noun1[2], noun[n]);
		}
	}

	for (k = 0; k<42; k++)
	{
		if (IsRhymes(noun1[4], noun[k]))
			strcpy_s(noun1[5], noun[k]);
	}

	if (strcmp(noun1[4], noun1[5]) == 0)
	{
		for (n = 41; n >0; n--)
		{
			if (IsRhymes(noun1[4], noun[n]))
				strcpy_s(noun1[5], noun[n]);
		}
	}

	i = rand() % 19;
	strcpy_s(verb1[0], verb[i]);

	i = rand() % 10;
	strcpy_s(verb1[1], verb[i]);

	i = rand() % 19;
	strcpy_s(adj1[0], adj[i]);

	i = rand() % 18;
	strcpy_s(adj1[1], adj[i]);

	i = rand() % 17;
	strcpy_s(adj1[2], adj[i]);

	i = rand() % 16;
	strcpy_s(adj1[3], adj[i]);

	i = rand() % 15;
	strcpy_s(adj1[4], adj[i]);

	i = rand() % 14;
	strcpy_s(adj1[5], adj[i]);


	for (j = 0; j <42; j++)
	{
		if (IsRhymes(noun1[2], noun[j]))
			strcpy_s(noun1[3], noun[j]);
	}

	if (strcmp(noun1[2], noun1[3]) == 0)
	{
		//std::cout << "The same word" << std::endl;
		for (l = 41; l>0; l--)
		{
			if (IsRhymes(noun1[2], noun[l]))
				strcpy_s(noun1[3], noun[l]);
		}
	}
}

char *ReturnThreeFromTheRight(char*string)
{
	char *ptr;
	int length;

	ptr = string;

	length = strlen(string);

	ptr = ptr + (length - 3);

	return ptr;
}

int IsRhymes(char *word1, char *word2)
{
	int i;

	char *ptr1, *ptr2;

	ptr1 = word1;
	ptr2 = word2;

	ptr1 = ReturnThreeFromTheRight(word1);

	ptr2 = ReturnThreeFromTheRight(word2);

	if (strcmp(ptr1, ptr2) == 0)

		i = 1;
	else
		i = 0;
	return i;
}

void WritePoem(char noun1[][20], char verb1[][20], char adj1[][20])
{
	std::cout << "A " << adj1[0] << " " << noun1[0] << " like a " << adj1[1] << " " << noun1[1] << std::endl;
	std::cout << verb1[0] << " a " << adj1[2] << " " << noun1[2] << std::endl;
	std::cout << " A " << adj1[3] << " " << noun1[3] << " like a " << adj1[4] << " " << noun1[4] << std::endl;
	std::cout << verb1[1] << " a " << adj1[5] << " " << noun1[5] << std::endl;
	std::cout << '\n';
	std::cout << '\n';
}





Our dog needs urgent surgery, and the cost is overwhelming.

Any help, big or small, would mean the world to us. Thank you for supporting Oscar on his journey to recovery!



Oscar Story.

Oscar wasn’t just any puppy—he was a gift from a mother who trusted us with her smallest one.

For five years, my wife worked at the Indian Medical Center in Arizona, deep in Navajo Nation. Near her clinic, she often saw a homeless dog wandering the area. Over time, she began feeding her, and the dog grew fond of her. Then, one day, that same dog brought her newborn puppies to my wife—as if proudly showing them off.

Among them was the smallest, most delicate pup. My wife couldn’t resist. She brought him home, and we named him Oscar.

Oscar thrived in the house provided by the medical center, enjoying the big backyard where he lived. I built him a sturdy wooden doghouse, and we often took him on walks along the Window Rock Trail. He became our adventure companion, making the vast desert feel like home.

After my wife’s contract ended, we moved back to Florida, bringing Oscar with us. He adjusted to his new surroundings, but he never lost his adventurous spirit.

Now, Oscar faces a tough challenge—he needs urgent surgery, and the cost is overwhelming. We want to give him the best care possible, just as he’s given us years of joy and loyalty.

Any help, big or small, would mean the world to us. Thank you for supporting Oscar on his journey to recovery!