Question
using simple and basic C++

I.(a) A 6 X6 array, arr, is filled to capacity with integers. Write code to find and print: (i) the sum of the negative integ
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

a)

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main(){
   srand(time(NULL));
   const int SIZE=6;
   int negNosSum=0;
int arr[SIZE][SIZE];


for(int i=0;i<SIZE;i++)
{
    for(int j=0;j<SIZE;j++)
    {
        arr[i][j]=rand()%(21)-10;
   }
}

cout<<"____ Displaying the array ___"<<endl;
for(int i=0;i<SIZE;i++)
{
    for(int j=0;j<SIZE;j++)
    {
    cout<<arr[i][j]<<"\t";  
            if(arr[i][j]<0)
            {
                negNosSum+=arr[i][j];
           }
}
cout<<endl;
}
  
cout<<"Sum of Negative Values :"<<negNosSum<<endl;
cout<<"Displaying the diagonal Elements :";
for(int i=0;i<SIZE;i++)
{
    for(int j=0;j<SIZE;j++)
    {
        if(i==j)
        {
            cout<<arr[i][j]<<" ";
       }
    }
}
cout<<endl;
int temp;
   for(int i=0;i<SIZE;i++)
   {

           temp=arr[i][0];
           arr[i][0]=arr[i][1];
           arr[i][1]=temp;
      
   }
   cout<<"____ Displaying the array after Interchanging first and second columns___"<<endl;
for(int i=0;i<SIZE;i++)
{
    for(int j=0;j<SIZE;j++)
    {
    cout<<arr[i][j]<<"\t";  
            if(arr[i][j]<0)
            {
                negNosSum+=arr[i][j];
           }
}
cout<<endl;
}
  
return 0;
  
}

__________________________

Output:

CAProgram Files (x86)\Dev-Cpp\MinGW64\bin\ArraySumOfNegativeNosDiagonalElements.exe Displaying the array 9 -9 -10 2 -10 2 Sum

____________________

b)

#include <iostream>
using namespace std;

string getInput();
void convertToUpper(string &str);
void reverseString(string &str);
void upwardTwoPlaces(string &str);
int main(){


string res=getInput();
   cout<<"Result :"<<res<<endl;
  
return 0;
  
}
string getInput()
{
   string str;
   cout<<"Enter String :";
   cin>>str;
   convertToUpper(str);
   reverseString(str);
   upwardTwoPlaces(str);
   return str;
}
void convertToUpper(string &str)
{
   string s="";
   char ch;
   for(int i=0;i<str.length();i++)
   {
       ch=str.at(i);
       if(ch>='a' && ch<='z')
       {
       s+=ch-32;  
       }
       else
       {
       s+=ch;  
       }
   }
   str=s;
}
void reverseString(string &str)
{
   string rev="";
   for(int i=str.length()-1;i>=0;i--)
   {
       rev+=str.at(i);
   }
   str=rev;
  
}
void upwardTwoPlaces(string &str)
{
   string s="";
   for(int i=0;i<str.length();i++)
   {
       if(str.at(i)=='Y')
       {
           s+='A';
       }
       else if(str.at(i)=='Z')
       {
           s+='B';
       }
       else
       {
           s+=str.at(i)+2;
       }
   }
   str=s;
}
_______________________

Output:

CAProgram Files (x86)\Dev-Cpp\MinGW64\bin\ConvertLowerToUpperReverseString.exe Enter String :abxzyc Result EABZDC Process exi

_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
using simple and basic C++ I.(a) A 6 X6 array, arr, is filled to capacity with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a full C++program to do the following processes on a two dimension array of integers....

    Write a full C++program to do the following processes on a two dimension array of integers. Assume the size is 4x4 . 1- Fill the array with the numbers like this pattern: 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 Note: Do not accept the values as input, or hard code it. Find the math to generate these numbers and fill the array with them.    2- Reset the main diagonal elements...

  • (JAVA) Given an array of unique positive integers, write a function findSums that takes the array...

    (JAVA) Given an array of unique positive integers, write a function findSums that takes the array input and: 1. Creates a hashtable called “hashT” and inserts all the elements of the input array in the hashtable. 2. Finds pairs of elements in the hashtable whose sum is another element (sum) in the hashtable and print the pairs in the console. 3. Returns another hashtable names “sums” of those sum elements. For example: Input: [1,5,4,6,7,9] Output: [6,5,7,9] Explanation: 6 = 1...

  • How would answer question #4 of this ? #1 and 2 #include<iostream> #include <fstream> using namespace...

    How would answer question #4 of this ? #1 and 2 #include<iostream> #include <fstream> using namespace std; void read(int arr[]) {    string line;    ifstream myfile("input.txt");    int i = 0;    if (myfile.is_open())    {        while (getline(myfile, line))        {            arr[i];            i++;        }        myfile.close();    } } void output(int arr[]) {    ofstream myfile("output.txt");    if (myfile.is_open())    {        int i = 0;...

  • Using C programming

    Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...

  • Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory...

    Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int * ) named ptr_1. Use ptr_1 to assign the number 7 to that dynamically allocated integer, and in another line use printf to output the contents of that dynamically allocated integer variable. Write the code to dynamically allocate an integer array of length 5 using calloc or malloc and have it pointed...

  • This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to...

    This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...

  • Please help me write this Java program. I had posted this question before, but got an...

    Please help me write this Java program. I had posted this question before, but got an answer that was totally wrong. We are using the latest version of Java8. Thank You! -------------------------------------------------------------------------------------- Write a Java program that can successfully DECRYPT a string inputted by the user which has been encrypted using a Caesar Cipher with a unknown shift value(key). You can use brute force to do a for loop through all the 26 shift values, however, your program should only...

  • In basic c develop the code below: (a) You will write a program that will do...

    In basic c develop the code below: (a) You will write a program that will do the following: prompt the user enter characters from the keyboard, you will read the characters until reading the letter ‘X’ You will compute statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character ‘X’. Example input mJ0*5/]+x1@3qcxX The ‘X’ should not be included when computing the statistics...

  • I need eclipse code for : Write a program that analyzes text written in the console...

    I need eclipse code for : Write a program that analyzes text written in the console by counting the number of times each of the 26 letters in the alphabet occurs. Uppercase and lowercase letters should be counted together (for example, both ‘A’ and ‘a’ should count as an A). Any characters that are not letters should be ignored. You must prompt the user to enter the text to be analyzed. Then, for any letter that appeared at least once...

  • 8.16 Ch 8, Part 1: XOR Cipher Write this program using Eclipse. Comment and style the...

    8.16 Ch 8, Part 1: XOR Cipher Write this program using Eclipse. Comment and style the code according to CS 200 Style Guide. Submit the source code files (.java) below. Make sure your source files are encoded in UTF-8. Some strange compiler errors are due to the text encoding not being correct. This program will implement a simple XOR cipher on an integer array, where the data to be encoded is XOR'd with a key. This idea is often used...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT