1.1
#include<iostream>
#include<string>
using namespace std;
bool areFirstTwoTheSameAsLastTwo(string str)
{
if (str.length() == 0 || str.length() == 1)
return false;
string firstTwo, lastTwo;
firstTwo = str.substr(0, 2);
lastTwo = str.substr(str.length() - 2);
return (firstTwo == lastTwo);
}
int main()
{
cout << "" <<" =
"<<areFirstTwoTheSameAsLastTwo("") << endl;
cout << "A" << " = " <<
areFirstTwoTheSameAsLastTwo("A") << endl;
cout << "AB" << " = " <<
areFirstTwoTheSameAsLastTwo("AB") << endl;
cout << "ABA" << " = " <<
areFirstTwoTheSameAsLastTwo("ABA") << endl;
cout << "ABAB" << " = " <<
areFirstTwoTheSameAsLastTwo("ABAB") << endl;
system("pause");
return 0;
}
output
1.2
#include<iostream>
using namespace std;
int checkGradeList(char grade[], int size)
{
int count = 0;
for (int i = 0; i < size; i++)
{
int isValidate = (grade[i] == 'A'
|| grade[i] == 'a' || grade[i] == 'B' || grade[i] == 'b' ||
grade[i] == 'C' || grade[i] == 'c' || grade[i] == 'D' || grade[i]
== 'd' || grade[i] == 'F' || grade[i] == 'f');
if (!isValidate)
{
grade[i]
='I';
count++;
}
}
return count;
}
int main()
{
char grade[] = { 'A','B','X','C' };
cout <<"Total invalid grade: "<<
checkGradeList(grade, 4)<<endl;
cout << "Grades after validation: " <<
endl;
for (int i = 0; i < 4; i++)
{
cout<<grade[i] <<
endl;
}
system("pause");
return 1;
}
output
1.3
#include<iostream>
using namespace std;
bool isTheSamllestLast(int &smallest)
{
int num, count = 0,lastNum;
cout << "Enter a number and 0 to stop: ";
cin >> num;
while (num > 0)
{
if (count == 0)
{
smallest =
num;
lastNum =
num;
}
if (num < smallest)
smallest =
num;
cout << "Enter a number and 0
to stop: ";
cin >> num;
count++;
}
if (count == 0)
{
smallest = 0;
return 0;
}
if(count==1)
{
return true;
}
if (lastNum <= smallest)
return true;
return false;
}
int main()
{
int smallest;
if(isTheSamllestLast(smallest))
{
cout << "Lat num is
smallest." << endl;
}
else
{
cout << "Lat num is not
smallest." << endl;
}
cout << "Smallest nume is: " << smallest
<< endl;
system("pause");
return 1;
}
output
1.4
#include<iostream>
using namespace std;
bool checkYourGrade()
{
char grade;
cout << "Please enter your grade: ";
cin >> grade;
int count = 1;
while (true)
{
if (grade == 'A' || grade == 'B' ||
grade == 'C' || grade == 'D' || grade == 'F')
break;
if (count == 3)
return
false;
cout << "Invalid grade.
Please try again.";
cout << "Please enter your
grade: ";
cin >> grade;
count++;
}
if (grade == 'A' || grade == 'B' || grade ==
'C')
return true;
return false;
}
int main()
{
cout << (checkYourGrade() ? "Passed" : "Failed")
<< endl;
system("pause");
return 0;
}
outputs



1.5
#include<iostream>
using namespace std;
int GetScoreTotalWithoutHigLow()
{
int min, max, total=0, count = 0,num;
while (true)
{
cout << "Please enter
non=negative score: ";
cin >> num;
if (num < 0)
break;
if (count == 0)
{
min = num;
max = num;
}
count++;
total += num;
if (num < min)
min = num;
if (max < num)
max = num;
}
if (count <= 2)
return 0;
return total - min - max;
}
int main()
{
cout <<"The total is : "<<
GetScoreTotalWithoutHigLow() << endl;
system("pause");
return 0;
}
output
If you have any query regarding the code
please ask me in the comment i am here for help you. Please do not
direct thumbs down just ask if you have any query. And if you like
my work then please appreciates with up vote. Thank You.
1.1. Write a function named "areFirstTwoTheSame AsLast TwoChars" that accepts a string. It returns true if...
C++ Write a function named “hasDescendingDigits” that accepts a string of numbers. It returns true if the string contains the digits in descending order. The function can ignore (e.g. skip checking) all the characters that are not digits in the string. Empty string will return false. For example, string of “95421” or “862” or “8622” or “88” or “9” will return true and string of “95423” or “889” or “9445” or “449” or “” will return false.
Design a function named max that accepts two integer values as arguments and returns the value that is the greater of the two. For example, if 7 and 12 are passed as arguments to the function, the function should return 12. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is the greater of the two. Need Variable lists, Psuedocode, ipo chart, Flow Chart, and a python...
1. Write a function named “areFirstTwoTheSameAsTheLastTwo” that accepts an array of integers, its size and return true if the first two numbers in the array are the same as the last two numbers in the array. It returns false otherwise. If the array has less than 4 elements, it always returns false. For example, this array of {10, 20, 30, 40, 10, 20} or {10, 20, 10, 20} will return true but this array of {10, 20, 20, 10} or...
C++ //get_letter_grade.h /* Write a function gpa_to_letter_grade that returns a string and accepts a double gpa parameter */ //get_letter_grade.cpp /* Write function code for gpa_to_letter_grade that returns a string and accepts a double gpa parameter YOU MUST USE A SWITCH STATEMENT Given a double 3.5 returns the string A TIP: You'll have to convert the double to an int using multiplication Table 3.5 to 4 returns an A 3.0 to 3.49 returns a B 1.7 to 2.99 returns a C...
Write a function named vertical that accepts a string as its parameter and prints each letter of the string on separate lines. For example, a call of vertical("hey now") should produce the following output: h e y n o w
JAVA~ 1. Write a static method named countOdd(my_array) that returns the number of odd integers in a given array. If there are no odd numbers in the array, the method should return 0. If the array is empty, the method should also return 0. For example: Test Result System.out.println(countOdd(new int[]{2, 3, 5, 6})); 2 System.out.println(countOdd(new int[]{2})); 0 System.out.println(countOdd(new int[]{})); 0 System.out.println(countOdd(new int[]{-7, 2, 3, 8, 6, 6, 75, 38, 3, 2})); 4 public static int ----------------------------------------------------------------------------------------------------------- 2. Write a static...
Write a function check palindrome, which takes a string x as argument and which returns True if x is a palindrome, and False otherwise. A palindrome is a word that reads the same backwards as forwards (like for example “racecar”). Your function should be recursive (i.e. call itself) and proceed as follows. 1. If x is a string of length 0 or 1 return True. 2. If the rst and the last letter of x are di erent, return False....
Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...
Write a method in java named isValidEmail that takes a string as input parameter, and returns true if that string represents a valid email address, or false otherwise. An email address is considered valid if it follows this format “user123@domain.ext”, where: user123 represents a sequence of word characters (i.e., letters, digits, or underscore) whose length is between 1 and 10 (inclusive), but the first character must be a letter domain represents a sequence of alphanumeric characters (i.e., letters...
Python Programming Assignment: Write a function to take a string S that returns True if the letters are in ascending order and False otherwise. To do this go over each letter and check that it is less than the letter that precedes it. Then write a function main that gets one input from the user, then if passing that input to the function above returns True, then show "String is in order", otherwise show " String is unordered".