since multiple questions are given, I'm solving the first question
#include <iostream>
using namespace std;
// we can easily implement stack using likned list
// we maintain a linked list and always push and pop the element
from the front ton maintain the LIFO(last in first out)
property
struct Stack{
char data;// to store the char of the string
Stack* next;// link to nexr node
};
Stack* top=NULL;// head or top the stack
// function to push the char in stack
void push(char s)
{
Stack* temp=new Stack();// dynammically allocating a new node
temp->data=s;// setting the node's data to s
temp->next=top;
top=temp;// adjusting the link to add the new node in the front of
the linked list
}
// function to remove element from the top
void pop(){
Stack* temp=top;//storing the element to be deleted in temporary
variable
top=top->next;// makin the next element as the front
element
temp->next=NULL;// breaking the connection between the second
element and the element to be deleted
free(temp);// freeing the memory
}
// returns the data og top character
char peek()
{
return top->data;
}
// check if the stack is empty or not
bool isempty()
{
return top==NULL;
}
// the the Stack
void display()
{
Stack *temp=top;
while(temp)
{
cout<<temp->data<<" ";
temp=temp->next;
}
}
int main() {
// your code goes here
string s;
getline(cin,s);// getting input from the user
for(int i=0;i<s.length();i++)
{
if(s[i]>='A'&&s[i]<='Z')// converting
all uppercase letters to lower case letters
{
s[i]=s[i]+32;
}
push(s[i]);// now pushing all the letters in the
stack
}
// now since stack follow LIFO(last in first out),
element that were inserted at the last, will come out first, thus
the string will come out in rever order
char prev='\0';// we maintain a previous charcter, so
that when we encounter a space character we can convert its next
character into uppercase
while(!isempty())
{
char c=peek();
pop();
if(prev==' '||prev=='\0')
{
c=c-32;// converting into uppercase
}
cout<<c;
prev=c;// updating previous
}
return 0;
}
Sample Input: "Nguyen Van A"
Sample Output :"A Nav Neyugn"
Please upvote if you liked the answer.Thank you!
Exereise 1: 7 рoints Write a program in C/C++ to enter a string of characters i.e....
Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp { public static void main(String[] args) { displayWelcomeMessage(); // create the Scanner object Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // generate the random number and invite user to guess it int number = getRandomNumber(); displayPleaseGuessMessage(); // continue until the user guesses the number int guessNumber = 0; int counter = 1; while (guessNumber != number) { // get a valid int from user guessNumber...
please c++ with functions *Modify the Guessing Game Write the secret number to a file. Then write each user guess and answer to the file. (on separate lines) Write the number of guesses to the file at the end of the game. After the game is finished, ask the user if they want to play again. If 'n' or 'N' don't play again, otherwise play again! NOTE: your file should have more than one game in it if the user...
#include <iostream> #include <cstdlib> #include <time.h> #include <string> using namespace std; int main() { srand(time (0)); int number, guess, response, reply; int score = 0 number = rand() % 100 + 1; do { do { cout << "Enter your guess "; cin >> guess; score++; if (guess < number) cout << guess << " is too low! Enter a higher number. "; else if (guess > number) cout << guess << " is too high! Enter a lower number....
Write a C++ program that will determine if one input string is a subsequence of a second input string. In a subsequence, all the characters in the first string will also be in the second string in the same order. For example: “abc” is a subsequence of “qzabc”. While the characters must be in the same order, they do not have to be consecutive. For example: “abc” is also a subsequence of “aaqbzcw”. We will use two stacks one and...
Please write a C# program that where a player will play a guessing game with the range of 1-100. Each time the play guesses a number, and it is not correct the program should indicate if the number is more or less than what the player guessed. The play should be able to guess until the correct number has been guessed. If an invalid number is entered, such as: 1.24 (real number), or asd (string). The program should tell user...
Q.1. Write a C program that determines whether a line entered by a user is a palindrome or not. You must demonstrate it as an application of stack (you may use linked list implementation demonstrated in the class). Hint! Think of the basic property of a stack i.e. LIFO (list-in-first-out). Q.2. Write a charQueue header file containing all the function headers of following functions: 1- initiateQueue—to initialize a queue 2- enqueue—to add a node at the rear end of the...
Create a new program, WordGuessingGame. Using a while loop, create a game for the user. The game requires the user to guess a secret word. The game does not end until the user guesses the word. After they win the game, they are prompted to choose to play again. The secret word that user must guess is "valentine". It is a case-sensitive analysis With each guess... If the guess does not have an equal number of characters, tell the user...
Specification Write a program that allows the user to play number guessing games. Playing a Guessing Game Use rand() function from the Standard C Library to generate a random number between 1 and 100 (inclusive). Prompt the user to enter a guess. Loop until the user guesses the random number or enters a sentinel value (-1) to give up. Print an error message if the user enters a number that is not between 1 and 100. Print an error message...
Required in JAVA language Write a program that enables a user to play number guessing games. The following is a nutshell description of a number guessing game. + a random number is generated + loop prompting the user to enter guesses until the user guesses the number or hits the maximum number of allowed guesses or enters the "quit" sentinel value The rest of this specification documents number guessing games in more detail. The documentation uses manifest constants that can...
python question
Question 1 Write a Python program to play two games. The program should be menu driven and should use different functions to play each game. Call the file containing your program fun games.py. Your program should include the following functions: • function guess The Number which implements the number guessing game. This game is played against the computer and outputs the result of the game (win/lose) as well as number of guesses the user made to during the...