0% found this document useful (0 votes)
12 views

Oops Ass

Uploaded by

dhroovkumar572
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Oops Ass

Uploaded by

dhroovkumar572
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Computer Science and Engineering

PROGRAMMING FOR PROBLEM SOLVING


UES103

SUBMITTED BY:
Name- ______________________
Roll No.- _____________________
Group- _______________________
INDEX
Assignment 1:

Q1. Perform Redo and Undo Operation using C++


Sol.
#include <iostream>
#include <string>
using namespace std;

int main() {
string history[100];
int currentIndex = -1;
string content;
int choice;
string text;

do {
cout << "\nMenu:\n";
cout << "1. Add Text\n";
cout << "2. Undo\n";
cout << "3. Redo\n";
cout << "4. Display Content\n";
cout << "5. Exit\n";
cout << "Enter your choice: ";
cin >> choice;

switch (choice) {
case 1:
// Add text
cout << "Enter text to add: ";
cin.ignore();
getline(cin, text);
content += text;

// Save the new state in history and update currentIndex


currentIndex++;
history[currentIndex] = content;

// Clear any redo history if we add new text


for (int i = currentIndex + 1; i < 100; ++i) {
history[i] = ""; // Clear the redo history
}
break;

case 2:
// Undo operation
if (currentIndex <= 0) {
cout << "Nothing to undo." << endl;
} else {
currentIndex--;
content = history[currentIndex];
}
break;
case 3:
// Redo operation
if (currentIndex >= 99 || history[currentIndex + 1] == "") {
cout << "Nothing to redo." << endl;
} else {
currentIndex++;
content = history[currentIndex];
}
break;

case 4:
// Display the current content
cout << "Current Content: " << content << endl;
break;

case 5:
cout << "Exiting..." << endl;
break;

default:
cout << "Invalid choice, please try again." << endl;
}
} while (choice != 5);

return 0;}
Assignment 2

a) Write a C++ program to find the sum of individual digits of a positive integer.

b) Write a C++ program to generate the first n terms of the sequence.

c) Write a C++ program to generate all the prime numbers between 1 and n,
where n is a value
supplied by the user.

d) Write a C++ program to find both the largest and smallest number in a list of
integers.

a)
#include <iostream>
using namespace std;
int main() {
int number, sum = 0;
cout << "Enter a positive integer: ";
cin >> number;

// Calculate the sum of digits


while (number > 0) {
sum += number % 10; // Add the last digit to sum
number /= 10; // Remove the last digit
}
cout << "Sum of the digits: " << sum << endl;
return 0;
}
b)

You might also like