Search This Blog

Thursday, 21 June 2018

CS201 Introduction to Programming - Assignment 2

// Assignment No.2
//Write a program in C++ that will ask some programming related questions ()
//from user and rank user according his / her answers in one of following categories:
//1- Beginner level
//2- Intermediate level
//3- Advanced level


#include <iostream>

using namespace std; //Allows computer to output data

const int TotQtn = 2; //define contant for total questions

char getinputs(char[]); //declare function to get input from user

int computeUserLevel(char*); //declare function to computer user level

main() //main function begins
{
//declare variables and array
int rank;
char option[TotQtn];

cout << "\t\t\"Program to Predict User Programming Level\"\n\n";

//get inputs from the user
getinputs(option);

//compute the rank of the user
rank=computeUserLevel(&option[0]);

switch (rank) //display result
{
case 3:
cout << "Your level is advanced";
break;

case 2:
cout << "Your level is Intermediate";
break;

default:
cout << "Your level is Beginner";
}
}//end of main function


//function which get the answer as inputs in the array
char getinputs(char ans[])
{
int q=0;
for(q=0;q<=TotQtn;q++)
{
if (q==0)
{
cout << "Q: Switch is a loop?\nA: ";
cin >> ans[q];
}
else if (q==1)
{
cout<<"Q: Pointer Store memory addresses?\nA: ";
cin >> ans[q];
}
else if (q==2)
{
cout<<"Q: Semicolon after for loop is an error?\nA: ";
cin >> ans[q];
}
}
return ans[q];
}

//function that compute the user level
int computeUserLevel(char *op)
{

if (*op=='f' && *(op+1) == 't' && *(op+2) == 'f')
{
return 3;
}
else if (*op == 'f' && *(op+1) == 't' && *(op+2) == 't')
{
return 2;
}
else
return 1;
}

No comments:

Post a Comment