Answer to Question #196509 in C++ for Navya kala

Question #196509

A sender sends data of length 'l'in the form of digitset to the receiver where a digitset a collection of digits. The sender sends two data d1 and d2 to the receiver. The receive finds the sum of the data. While transmission, the digit in the highest value place of d1


is corrupted as 'm' more than the actual digit.


Note: 'm' is less than the digit in the highest value place


Given the length of the data 'l', data d1, d2 and the value 'm', develop pseudocode and


C++ code to the display the sum of d1 and d2 and the corrected d1 and corrected sum. Overload '+' operator to find the sum of data.


For example, if 'l' is 3 and d1 is 321 and d2 is 996 and 'm' is 1, then the sum is 1317, corrected d1 is 221 and the corrected sum is 1217.


Input format:


Enter the length of the data, I


Next 'l' lines contains digits of d1


Next 'l' lines contains digits of d2


Last line contains 'm'


Output format:


Sum of d1and d2


Next 'l' lines contains corrected data d1


Last line contains corrected sum




1
Expert's answer
2021-05-25T00:07:53-0400
#include <iostream>
#include <string>
using namespace std;


int main()
{
    int l;
    int d1,d2;
    string s1="";
    string s2;
    string s3="";
    string s4;
    cout<<"\nEnter the length of data:";
    cin>>l;
    cout<<"\nEnter lines contains digits of d1: ";
    for (int i=0;i<l;i++){
        cin>>s2;
        s1+=s2;
    }
    d1=stoi(s1);
    
    cout<<"\nEnter lines contains digits of d2: ";
    for (int i=0;i<l;i++){
        cin>>s4;
        s3+=s4;
    }
    
    d2=stoi(s3);
    int sum=d1+d2;
    cout<<"\nThe sum of d1 and d2 is "<<sum;
    int m;
    cout<<"\nEnter m: ";
    cin>>m;
    s1[0]=s1[0]-m;
    d1=stoi(s1);
    cout<<"\nThe corrected d1 is: "<<d1;
    int sum2=d1+d2;
    cout<<"\nThe corrected sum is: "<<sum2;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog