The More I Help Others To Succeed, The More I Succeed

CS201 Assignment Solution # 1 Fall 2021

Assignments 75
CS201 Assignment Solution # 1 Fall 2021

CS201 Assignment Solution # 1 Fall 2021

CS201 Assignment Solution # 1 Fall 2021

Assignment No.  1
Semester: Fall 2021

Due Date: 9 Dec 2021

Total Marks: 20

Code Solution:

include #include

using namespace std;

void printnameid(string studentid, string studentname); int calculatelastthreedigits(string studentid);

int main()
{

string studentid=”BC18020431″; // Student id

string studentname=”Muhammad Sarim”; // Student name

printnameid(studentid,studentname);
int TotalLastThreeDigits=calculatelastthreedigits(studentid); int counter=1;
int a,b,c;
// Students id last 3 digits a=4;
b=3; c=1;
cout<<“”<<endl;
cout<<“Sum of Last 3 digits is=”<<a+b+c<<endl; cout<<“”<<endl;
if ( TotalLastThreeDigits % 2 == 0) // Divide by 2 and see if the reminder is zero? then it is even otherwise it is odd number
{

cout<< ” Sum is an even value “<<endl; cout<<“”<<endl;

cout<<“++++++++++++++++++++++++++++++++++++++++++++
“<<endl;
cout<<“”<<endl;
while(counter <= TotalLastThreeDigits)
{

cout << ” Iteration: ” <<counter <<endl;
cout << “My student id is:” <<studentid<<endl; counter++;
}
}

else
{

cout << ” Sum is an odd value:”<<endl; while(counter <= TotalLastThreeDigits)
{

cout<< ” Iteration: “<<counter<<endl;
cout<< “My name is “<<studentname<<endl; counter++;

}
}

return 0;
}

void printnameid(string studentid, string studentname){ cout<<” My name “<<studentname <<endl;
cout<<” My student id is “<<studentid<<endl;

}

int calculatelastthreedigits(string studentid) {

int end=studentid.length(); // Ending point that is total length of string
int start=end-3; // Starting point
string lastthreedigits=studentid.substr(start,end); // Trim the last three digits;
int total=0;

//Calculate the sum of last three digits
for ( int index=0; index < lastthreedigits.length(); index++) { total += lastthreedigits[index] – ‘0’;
}
return total;
}

Code Solution Output :

CS201 Assignment Solution # 1 Fall 2021

CS201 Assignment Solution # 1 Fall 2021

CS201 Assignment Solution # 1 Fall 2021

CS201 Assignment Solution # 1 Fall 2021

For More Assignment Details

Leave a Reply

Your email address will not be published.

Be silent and let your success shout