Pages

CS201 ASSIGNMENT 1 SOLUTION FALL 2023 | CS201 ASSIGNMENT 1 SOLUTION 2023 | CS201 ASSIGNMENT 1 2023 | INTRODUCTION TO PROGRAMMING | VuTech

CS201 ASSIGNMENT 1 SOLUTION FALL 2023 | CS201 ASSIGNMENT 1 SOLUTION 2023 | CS201 ASSIGNMENT 1 2023 | INTRODUCTION TO PROGRAMMING | VuTech

CS201 ASSIGNMENT 1 SOLUTION FALL 2023 | CS201 ASSIGNMENT 1 SOLUTION 2023 | CS201 ASSIGNMENT 1 2023 | INTRODUCTION TO PROGRAMMING | VuTech

Visit Website For More Solutions
www.vutechofficial.blogspot.com

KINDLY, DON’T COPY PASTE

Question No. 1

Write a C++ program that performs the following tasks: 

Use only the provided Student ID: BC123456789 (In case of not using this ID, marks will be deducted.)

Your program must take the numerical part of the given Student ID BC123456789 which is 123456789.

  • Save the numerical part of the given ID in a variable.
  • Double (Multiply by 2) each digit and print each doubled digit in reverse order.
  • Calculate sum of all the doubled digits. 
  • Print the sum on screen.

Your program should use functions to complete the above tasks. You will define doubleDigits() function which will double of each digit and print, and sumOfDoubledDigits () function to calculate the sum of the doubled digits.

Solution:

#include <iostream>

#include <string>

#include <cstdlib>

using namespace std;


void doubleDigits(int num){

while(num > 0){

int digit = num % 10;

int doubled_digit = digit * 2;

cout<<"Separated digits doubled : " << doubled_digit<<endl;

num /= 10;

}

}


int sumOfDoubledDigits(int num){

int sum = 0;

while(num > 0){

int digit = num % 10;

int doubled_digit = digit * 2;

sum += doubled_digit;

num /= 10;

}

return sum;

}


int main(){

string studentID = "MC123456789";

string numericalPart = studentID.substr(2);

int numericValue = atoi(numericalPart.c_str());

cout<<"The given student ID is : " << studentID << endl;

cout<<"Give Student ID digital part is : " << numericalPart << endl;

doubleDigits(numericValue);

int sum = sumOfDoubledDigits(numericValue);

cout<< "Sum of Separated Doubled Digits :" << sum <<endl;

return 0;

}



KINDLY, DON’T COPY PASTE
SUBSCRIBE, SHARE, LIKE AND COMMENTS FOR MORE UPDATES
SEND WHATSAPP OR E-MAIL FOR ANY QUERY
0325-6644800
kamranhameedvu@gmail.com
Visit Website For More Solutions
www.vutechofficial.blogspot.com