COMPUTER PROGRAMMING
PROJECT
PROJECT TITLE:
THINK LIKE A CODER
NAME:
SYED MEHMOOD-UL- HASAN
ENROLLMENT NO:
01-135232-113
CLASS:
BS (IT) 2-A
Submitted to:
Respected Sir JUNAID HUSSAIN
DEPARTMENT OF COMPUTER SCEINCE
BAHRIA UNIVERSITY ISLAMABAD
EPISODE # 1:
#include <iostream>
using namespace std;
void checklock(int open, int limit)
{
for (int i = 1; i <= limit; i++)
{
if (open == i)
{
cout << "Lock is open at " << i << " turn...";
return;
}
}
}
int main()
{
int limit = 100;
int open = 1 + (rand() % limit);
checklock(open, limit);
return 0;
}
Explanations:
This C++ code generates a random turn out of 100 and checks if the lock opens at
that turn. If the turn matches the randomly generated one, it prints a message
indicating that the lock is open.
EPISODE # 2:
#include <iostream>
#include <string>
using namespace std;
bool isVowel(char ch)
{
return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'y'||
ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U' || ch == 'Y');
}
int countvowels(string name)
{
int vowelCount = 0;
for (char ch : name)
{
if (isVowel(ch))
{
vowelCount++;
}
}
return vowelCount;
}
bool hasConsecutiveDoubleLetters(string name)
{
for (int i = 0; i < [Link]() - 1; i++)
{
if (name[i] == name[i + 1])
{
return true;
}
}
return false;
}
void analyzeLeader(string name, string characteristics)
{
// Green-eye check
if (characteristics[0] == '1')
{
// Red-hair check
if (characteristics[1] == '1')
{
// Check for consecutive double letters
if (hasConsecutiveDoubleLetters(name))
{
cout << name << " has green eyes, red hair, and a name with
consecutive double letters." << endl;
}
}
else
{
// Check for glasses and vowel count
if (characteristics[2] == '1')
{
// Exactly 2 vowels
if (countvowels(name) == 2)
{
cout << name << " has green eyes, not red hair, wears glasses, and
exactly 2 vowels." << endl;
}
}
else {
// Exactly 3 vowels
if (countvowels(name) == 3)
{
cout << name << " has green eyes, not red hair, doesn't wear
glasses, and exactly 3 vowels." << endl;
}
}
}
}
}
int main()
{
string resistance_leader_names[19] = { "Ali", "Serin", "Abby", "Jayden",
"Hayko", "Tolgo", "Ethan", "David", "Aaron",
"Han", "Grace", "Martin", "Elijah", "Sena", "Adila",
"Brody", "Isabel", "Jorge", "Esther" };
string resistance_leader_characteristics[19] = { "000", "001", "011", "111",
"110", "100", "101", "010", "000", "001",
"011", "111", "110", "100", "100", "101", "010",
"000", "001" };
for (int i = 0; i < 19; i++)
{
analyzeLeader(resistance_leader_names[i],
resistance_leader_characteristics[i]);
}
return 0;
}
Explanations:
This code checks characteristics of resistance leaders. It has an array of leader
names and another array with coded strings (likely 0s and 1s). It loops through
leaders, checks their code for eye color, hair color (possibly glasses), and then
based on the code, might check their name for things like double letters or vowel
count.
EPISODE #3:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void generateserial(int serial[], int size)
{
for (int i = 0; i < size; ++i)
{
int randomnumber;
bool exists;
do {
randomnumber = 1 + (rand() % 100);
exists = false;
for (int j = 0; j < i; ++j)
{
if (serial[j] == randomnumber)
{
exists = true;
break;
}
}
} while (exists);
serial[i] = randomnumber;
}
}
int findparent(int serial[], int size)
{
return serial[0];
}
int main()
{
const int lenght = 10;
int botsserials[lenght];
for (int i = 0; i < lenght; ++i)
{
botsserials[i] = i + 1;
}
generateserial(botsserials, lenght);
cout << "Serial Numbers of All Bots are : " << endl;
for (int i = 0; i < lenght; ++i)
{
cout << botsserials[i] << endl;
}
cout << endl << "Serial Number of Parent Bot is: " << findparent(botsserials, lenght);
return 0;
}
Explanations:
This code simulates assigning unique serial numbers to 10 robots. It avoids duplicates by
checking if a generated number already exists in the list. The generateserial() function
handles this. Finally, it identifies the "parent bot" (likely the first one created) using the
findparent() function and displays all serial numbers.