Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
ae817e0
fix: cpp-programming/Lab_20/Person.cpp — Precogs AI auto-fix
sameer6pre Mar 30, 2026
a27bcc4
fix: cpp-programming/Lab_02/01_temperature_converter.cpp — Precogs AI…
sameer6pre Mar 30, 2026
38cf7a3
fix: cpp-programming/Lab_02/06_leap_year.cpp — Precogs AI auto-fix
sameer6pre Mar 30, 2026
3242e26
fix: cpp-programming/Lab_02/04_vowel_consonant.cpp — Precogs AI auto-fix
sameer6pre Mar 30, 2026
e853dca
fix: cpp-programming/Lab_02/03_negative_positive.cpp — Precogs AI aut…
sameer6pre Mar 30, 2026
20a9123
fix: cpp-programming/Lab_02/05_largest_number.cpp — Precogs AI auto-fix
sameer6pre Mar 30, 2026
24a9db0
fix: cpp-programming/Lab_02/02_odd_even.cpp — Precogs AI auto-fix
sameer6pre Mar 30, 2026
4741ef2
fix: cpp-programming/Lab_05/Source.cpp — Precogs AI auto-fix
sameer6pre Mar 30, 2026
06221fb
fix: cpp-programming/Lab_05/Source1.cpp — Precogs AI auto-fix
sameer6pre Mar 30, 2026
7b2a83d
fix: Lab_05/Source3.cpp — Precogs AI auto-fix
sameer6pre Mar 30, 2026
49a4a9f
fix: Lab_05/Source2.cpp — Precogs AI auto-fix
sameer6pre Mar 30, 2026
91e74ec
fix: Project_E-Commerce_App_V2.0/main.cpp — Precogs AI auto-fix
sameer6pre Mar 30, 2026
e162219
fix: cpp-programming/Lab_04/Source.cpp — Precogs AI auto-fix
sameer6pre Mar 30, 2026
bf8e0fe
fix: cpp-programming/Lab_04/Source4.cpp — Precogs AI auto-fix
sameer6pre Mar 30, 2026
e39828c
fix: cpp-programming/Lab_04/Source1.cpp — Precogs AI auto-fix
sameer6pre Mar 30, 2026
f8639fb
fix: cpp-programming/Lab_04/Source3.cpp — Precogs AI auto-fix
sameer6pre Mar 30, 2026
e13296b
fix: cpp-programming/Lab_04/Source2.cpp — Precogs AI auto-fix
sameer6pre Mar 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 40 additions & 17 deletions Lab_02/01_temperature_converter.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,49 @@
// C++ program that converts between Celsius and Fahrenheit temperatures based on user input.

#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <cctype>

using namespace std;

int main() {
float temp;
char unit;
float temp = 0.0f; // PRECOGS_FIX: initialize to avoid use of indeterminate value
char unit = '\0';

cout << "Enter the temperature: ";
string tempStr;
if (!getline(cin, tempStr)) {
cerr << "Failed to read temperature input." << endl;
return 1;
}

cout << "Enter the temperature: ";
cin >> temp;
// Validate and parse temperature string safely
{
stringstream ss(tempStr);
if (!(ss >> temp) || !(ss.eof())) {
cerr << "Invalid temperature. Please enter a numeric value." << endl;
return 1;
}
}

cout << "Enter the unit (C/F): ";
cin >> unit;
cout << "Enter the unit (C/F): ";
string unitStr;
if (!getline(cin, unitStr) || unitStr.empty()) {
cerr << "Failed to read unit input." << endl;
return 1;
}

if (unit == 'C') {
cout << "The temperature in Fahrenheit is " << (temp * 9 / 5) + 32 << "F." << endl;
} else if (unit == 'F') {
cout << "The temperature in Celsius is " << (temp - 32) * 5 / 9 << "C." << endl;
} else {
cout << "Invalid unit." << endl;
}
// Normalize and validate unit character
unit = static_cast<char>(toupper(static_cast<unsigned char>(unitStr[0]))); // PRECOGS_FIX: normalize to uppercase and bound to first character
if (unit == 'C') {
cout << fixed << setprecision(2);
cout << "The temperature in Fahrenheit is " << (temp * 9.0f / 5.0f) + 32.0f << "F." << endl;
} else if (unit == 'F') {
cout << fixed << setprecision(2);
cout << "The temperature in Celsius is " << (temp - 32.0f) * 5.0f / 9.0f << "C." << endl;
} else {
cout << "Invalid unit. Use 'C' or 'F'." << endl;
}

return 0;
}
return 0;
}
27 changes: 15 additions & 12 deletions Lab_02/02_odd_even.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
// Program to find whether given number is even or odd.

#include <iostream>
#include <limits>

using namespace std;

int main() {
int a;
cout << "Enter the number: ";
cin >> a;
int a = 0; // PRECOGS_FIX: initialize variable to avoid use of uninitialized memory
cout << "Enter the number: ";
if (!(cin >> a)) {
cerr << "Invalid input. Please enter a valid integer." << endl; // PRECOGS_FIX: validate extraction and fail fast on invalid input
return 1;
}

if (a % 2 == 0)
cout << "Your number is Even!" << endl;
else
cout << "Your number is Odd!" << endl;
if (a % 2 == 0)
cout << "Your number is Even!" << endl;
else
cout << "Your number is Odd!" << endl;

system("pause");
return 0;
}
system("pause");
return 0;
}
16 changes: 11 additions & 5 deletions Lab_02/03_negative_positive.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// C++ Program to Check Whether a Number is Positive or Negative.

#include <iostream>
#include <limits>

using namespace std;

int main() {
float number;

cout << "Enter a number: ";
cin >> number;
if (!(cin >> number)) {
cerr << "Invalid input. Please enter a numeric value." << endl;
return 1;
}

if (number > 0) {
cout << "The number is positive." << endl;
Expand All @@ -18,6 +20,10 @@ int main() {
cout << "The number is zero." << endl;
}

system("pause");
// Use a safe, portable method to pause for user input instead of calling system().
cin.ignore(numeric_limits<streamsize>::max(), '\n'); // PRECOGS_FIX: clear any leftover input/newline from previous extraction
cout << "Press Enter to continue...";
cin.get(); // PRECOGS_FIX: replace system("pause") with safe std::cin.get()

return 0;
}
}
36 changes: 28 additions & 8 deletions Lab_02/04_vowel_consonant.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
// C++ Program to Check Whether a Character is a Vowel or Consonant.

#include <iostream>
#include <string>
#include <limits>
#include <cctype>

using namespace std;

int main() {
char c;
string s;

cout << "Enter a character: ";
cin >> c;
if (!(cin >> s)) {
cerr << "Input error." << endl;
return 1;
}

if (s.empty()) {
cerr << "No input provided." << endl;
return 1;
}

if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') {
char c = s[0];
if (s.size() > 1) {
cerr << "Warning: more than one character entered; using first character." << endl;
}

if (!isalpha(static_cast<unsigned char>(c))) {
cout << "Input is not an alphabetic character." << endl;
} else if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') {
cout << "The character is a vowel." << endl;
} else {
cout << "The character is a consonant." << endl;
}

system("pause");
// PRECOGS_FIX: Removed use of system() to avoid invoking the OS command processor; use a safe, portable pause instead
cout << "Press Enter to continue..." << flush;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin.get();

return 0;
}
}
35 changes: 17 additions & 18 deletions Lab_02/05_largest_number.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
// Program to find greatest in 3 numbers

#include <iostream>
using namespace std;

int main()
{
float a, b, c;
cout << "Enter the 3 numbres: ";
cin >> a >> b >> c;

if (a >= b && a >= c)
cout << "The greatest number is " << a << ";" << endl;

if (b >= a && b >= c)
cout << "The greatest number is " << b << ";" << endl;
float a, b, c;
cout << "Enter the 3 numbers: ";
if (!(cin >> a >> b >> c)) {
cerr << "Invalid input. Please enter three numeric values." << endl;
return 1;
}

if (c >= a && c >= b)
cout << "The greatest number is " << c << ";" << endl;
else if (a == b == c)
cout << "All numbers are equal." << endl;
if (a == b && b == c)
cout << "All numbers are equal." << endl;
else if (a >= b && a >= c)
cout << "The greatest number is " << a << ";" << endl;
else if (b >= a && b >= c)
cout << "The greatest number is " << b << ";" << endl;
else
cout << "The greatest number is " << c << ";" << endl;

system("pause");
return 0;
}
// PRECOGS_FIX: Removed unsafe system() call to eliminate reliance on PATH/working-directory lookup and prevent execution of attacker-controlled binaries
return 0;
}
67 changes: 36 additions & 31 deletions Lab_02/06_leap_year.cpp
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
// Program to find that entered year is leap or not.

#include <iostream>
#include <sstream>
#include <string>
#include <climits>

using namespace std;

int main()
{
int year;
cout << "Enter a Year: ";
cin >> year;

if (year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0)
{
cout << "Given " << year << " year is a leap." << endl;
}
else
{
cout << "Given " << year << " year isn't a leap." << endl;
}
}
else
{
cout << "Given " << year << " year is a leap year." << endl;
}
}
else
{
cout << "Given " << year << " year isn't a leap." << endl;
}
system("pause");
return 0;
}
string line;
cout << "Enter a Year: ";
if (!std::getline(cin, line)) {
cerr << "Input error: no data received." << endl;
return 1;
}

// Parse input robustly and validate range
stringstream ss(line);
long long year_ll = 0;
if (!(ss >> year_ll) || !ss.eof()) {
cerr << "Invalid input. Please enter a valid integer year." << endl;
return 1;
}

if (year_ll < INT_MIN || year_ll > INT_MAX) {
cerr << "Year out of range." << endl;
return 1;
}

int year = static_cast<int>(year_ll); // PRECOGS_FIX: validate and safely parse user input into an int within bounds

bool isLeap = (year % 4 == 0) && ((year % 100 != 0) || (year % 400 == 0));

if (isLeap)
cout << "Given " << year << " year is a leap." << endl;
else
cout << "Given " << year << " year isn't a leap." << endl;

// PRECOGS_FIX: removed system("pause") to avoid executing platform-specific shell commands and reduce risk
return 0;
}
35 changes: 20 additions & 15 deletions Lab_04/Source.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
// Lab assignment #5
// ID:U1910049; Name: Zokirov Rustam
// Control structure - Nested Loop

#include <iostream>
#include <limits>

using namespace std;

int main()
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
cout << "*";
}
cout << endl;
}
system("pause");
return 0;
}
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
cout << "*";
}
cout << endl;
}

// PRECOGS_FIX: Removed unsafe system() call and replaced with a safe, cross-platform pause using std::cin
cout << "Press Enter to continue...";
// PRECOGS_FIX: Use std::cin.ignore to consume any leftover input and std::cin.get to wait for Enter without invoking a shell
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin.get();

return 0;
}
12 changes: 6 additions & 6 deletions Lab_04/Source1.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// Lab assignment #5
// ID:U1910049; Name:Zokirov Rustam
// Control structure - Nested Loop

#include <iostream>
#include <limits>
using namespace std;
int main2()
{
Expand All @@ -17,6 +14,9 @@ int main2()
}
cout << endl;
}
system("pause");

// PRECOGS_FIX: Removed use of system() to avoid invoking the OS shell; use a safe, standard input-based pause instead.
cout << "Press Enter to continue...";
cin.ignore(numeric_limits<streamsize>::max(), '\n');
return 0;
}
}
13 changes: 5 additions & 8 deletions Lab_04/Source2.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
// Lab assignment #5
// ID:U1910049; Name:Zokirov Rustam
// Control structure - Nested Loop

#include <iostream>
using namespace std;
int main3()
{
for (int i = 1; i <= 5; i += 2)
Expand All @@ -19,6 +13,9 @@ int main3()
}
cout << endl;
}
system("pause");

cout << "Press Enter to continue..." << std::flush;
// PRECOGS_FIX: Avoid invoking the shell via system(); use in-process standard input to wait for the user.
std::cin.get(); // PRECOGS_FIX: Wait for Enter press in a portable, safer way than system("pause")
return 0;
}
}
Loading