- CS201 Assignment 1 Solution Fall2021
- CS201 Assignment 1 Solution
- Download Assignment
Download CS201Assignment 1 Solution Fall2021
Sample:
// C201 Assignment No: 1 Fall2021
//virtual polytech
#include <iostream>
#include <string>
using namespace std;
void printnameid(string studentid, string studentname);
int calculatelastthreedigits(string studentid);
int main()
{
string studentid="bc123456789";
string studentname="Virtual Polytech";
printnameid(studentid,studentname);
int TotalLastThreeDigits=calculatelastthreedigits(studentid);
int counter=1;
int a,b,c;
a=6;
b=4;
c=0;
cout<<"Sum of Last Three Numbers ="<<a+b+c;
cout<<"\n\n";
if ( TotalLastThreeDigits % 2 == 0) // Divide by 2 and see if the reminder is zero? then it is even otherwise it is odd number
{
cout << "the sum is an even value: \n\n";
cout<<"++++++++++++++++++++++++++++++++++++++++++++ \n\n";
while(counter <= TotalLastThreeDigits)
{
cout << " Iteration: " << counter << "\n";
cout << "My student id is:" << studentid << "\n";
counter++;
}
}
else
{
cout << "the sum is an odd value: \n\n";
while(counter <= TotalLastThreeDigits)
{
cout << " Iteration: " << counter << "\n";
cout << "My name is " << studentname << "\n";
counter++;
}
}
return 0;
}
void printnameid(string studentid, string studentname){
cout<<"My name is " << studentname << "\n\n\n";
cout<<"My student id is:" << studentid << "\n\n\n";
}
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; // return the total to calling statement.
}
Download From Button
1 Comments
cs201-assignment-1-solution-fall2021
ReplyDelete