CS201P Assignment 1 solution 2022 File Download

CS201P Assignment 1 solution 2022 File Download

CS201P assignment 1 solution 2022 file download.

you can download CS201P  assignment file latest 2022 solution for fall 2022 students.

in This file you will get the solution of problem given in LMS assignment section.


   Problem Statement:

Sometimes in programming, there may be a need to run a block of code repeatedly. In general, the programming statements are executed in order. Different control structures offered by programming languages allow for more complex execution paths. A loop statement allows us to execute a statement or collection of statements multiple times. Conditional branching statement (if-else), on the other hand, controls the flow of execution of statements based on some condition. If the given condition is true, the code inside IF block is executed, otherwise Else block code is executed.

Now keeping in mind, the above discussed concepts,write a C++ program using FOR loop and If-Else statement  that performs the following tasks:

1.      Print your VU Id.

2.      Add first and last numeric digit of VU Id, and store the result in variable “sum”.

3.      Display the result of sum on screen.

4.      If sum is greater than 7 then print the “Welcome to VU”. Number of iterations of FOR loop should be equal to the sum.

5.      If sum is less than 7 then print the “Welcome to CS201P”. Number of iterations of FOR loop should be equal to the sum.

For example, suppose the student id is BC123456781. Then by adding first and last numeric digit of VU Id, we get the value of 2. In this case, program should print “Welcome to CS201P” for 2 times using FOR loop and vice versa.

Solution  Code:


#include <iostream>
using namespace std;
#include <sstream>
#include <string>
using namespace std;
 #include <bits/stdc++.h>
 
 
 int firstDigit(int n)
{
    // Remove last digit from number
    // till only one digit is left
    while (n >= 10)
        n /= 10;
     
    // return the first digit
    return n;
}
 
// Find the last digit
int lastDigit(int n)
{
    // return the last digit
    return (n % 10);
}
 
 
int splitString(string str)
{
    string alpha, num, special;
    
    for (int i=0; i<str.length(); i++)
    {
        if (isdigit(str[i]))
            num.push_back(str[i]);
        else if((str[i] >= 'A' && str[i] <= 'Z') ||
                (str[i] >= 'a' && str[i] <= 'z'))
            alpha.push_back(str[i]);
        else
            special.push_back(str[i]);
    }
 

stringstream geek(num);
int x;
geek >> x;

    return x;
}


int main() {
int sum;
string vuid="BC211400542";
int cc;
cc=splitString(vuid);
    cout<<"My VU Id is "<<vuid<<endl;
    sum=firstDigit(cc)+lastDigit(cc);
cout<<"The sum of first and last digit of VU ID is "<<sum<<endl;
    
    
for(int i = 0; i < 2; i++) {
if(sum>7){
cout<<"Iteration "<<i+1<<": Welcome to VU"<<"\n";
} else {
cout<<"Iteration "<<i+1<<": Welcome to CS201P"<<"\n";
}
}
    return 0;
    system("pause");
    
}





Download .CPP Assignment File Here
Download CS301 Assignment 1 solution 2022

 

Featured post