Skip to content

Instantly share code, notes, and snippets.

@HammadMaqbool
Last active April 18, 2022 18:33
Show Gist options
  • Save HammadMaqbool/79639d3322ea25db976daeedf91e3b31 to your computer and use it in GitHub Desktop.
Save HammadMaqbool/79639d3322ea25db976daeedf91e3b31 to your computer and use it in GitHub Desktop.
A C++ based program to produce random questions
a console-based application for school teachers.
This application will auto generate questions for Grades 1, 2, 3, 4 and 5.
Using this application teacher will be able to give different paper to each student
/*Program by Hammad Maqbool*/
#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
void QuestionGenerator(int amountofq, int grade);
int RandomNumProvider(int digitRange);
int main()
{
int UserChoice_=0; // To save userchoice
int NumberOfQ=0; // Loop helper
cout<<"1: First Grade.\n2: Second Grade.\n3: Third Grade.\n4: Fourth Grade.\n5: Fifth grade."<<endl;
cout<<"Please Select Grade, User number 1 to 5:";
cin>>UserChoice_;
if(UserChoice_==1)
{
cout<<"Enter number of questions you want to generate:";
cin>>NumberOfQ;
QuestionGenerator(NumberOfQ,10);
}
else if(UserChoice_==2)
{
cout<<"Enter number of questions you want to generate:";
cin>>NumberOfQ;
QuestionGenerator(NumberOfQ,100);
}
else if(UserChoice_==3)
{
cout<<"Enter number of questions you want to generate:";
cin>>NumberOfQ;
QuestionGenerator(NumberOfQ,1000);
}
else if(UserChoice_==4)
{
cout<<"Enter number of questions you want to generate:";
cin>>NumberOfQ;
QuestionGenerator(NumberOfQ,10000);
}
else if (UserChoice_==5)
{
cout<<"Enter number of questions you want to generate:";
cin>>NumberOfQ;
QuestionGenerator(NumberOfQ,100000);
}
else
{
cout<<"Invalid Choice!";
}
return 0;
}
void QuestionGenerator(int amountofq, int grade_)
{
int NewLiner = 0;
int RandomNum1=0;
int RandomNum2=0;
for(int i=1;i<=amountofq;i++)
{
RandomNum1 = RandomNumProvider(grade_);
RandomNum2 = RandomNumProvider(grade_);
if(RandomNum1>RandomNum2)
{
cout<<i<<". "<<"("<<RandomNum1<<"-"<<RandomNum2<<") = _________";
}
else
{
cout<<i<<". "<<"("<<RandomNum1<<"+"<<RandomNum2<<") = _________";
}
cout<<"\t";
NewLiner++;
if(NewLiner==3)
{
cout<<endl;
NewLiner=0;
}
}
}
int RandomNumProvider(int DigitRange)
{
int localDigit = DigitRange;
int Generated = localDigit +rand() % localDigit;
return Generated;
}
//This Program is coded by HammadMaqbool for learning Purpose...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment