CodeGraderBench/CodeGraderBench huggingface dataset:
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in alphabetical order, -1 if the second string appears before the first in alphabetical order, and 0 if the two strings are equal to each other. Do not use the inbuilt strcmp function.
A function string_sort which sorts the character strings using the mergesort algorithm taught in class. You are recommended to write a recursive implementation. You will automatically lose 50% of the marks for this program if you implemented the sorting within main.
Your program should then print out the strings in sorted alphabetical order, starting from the first to the last. Feel free to refer to the lecture slides for help.

Input Format
integer n, and a set of n character strings


Output Format
Print out the strings in the suggested order, one string on a new line


Constraints
n is a positive integer, n <= 15
For ease of display of the output, the maximum length of any of the strings should be 11, excluding the NULL character
The character strings should contain only lower case alphabets


Sample input and output




Input

Output

4

zebra

lion

tiger

monkey



lion

monkey

tiger

zebra







Note:  

Do not write any C++ statements for printing general messages. For example, the following should NOT be present in your program: 
cout << "Enter a number:",  
cout << "The computed answer is", etc.  


cout should be used to print only the computed final output. In addition, do not print unnecessary spaces unless specified in the program.

Student submission:
/*
A triangular number counts the number of objects arranged in an equilateral triangle.
It turns out that the nth triangular number is equal to the sum of the n natural numbers from 1 to n. 
A diagram is shown here below. 
Your task is to write a C++ program with a function which returns true if the number is triangular
and false otherwise. 
To get points, the logic of your code needs to be correct, and you must write a function. 
Your code should print 1 if the number is triangular and 0 if it is not triangular. 
*/
#include <iostream>
using namespace std;

bool f(int x){

bool flag=false;

for(int i=1; 2*x-i*(i+1)>=0; i++){
        if(2*x-i*(i+1)==0) flag=true;
}
return flag;
}

int main(){
int x;
cin>>x;
if(f(x)) cout<<"1"<<endl;
else cout<<"0"<<endl;
}

Grading criterion: Merge sort algorithm
Rating A: Fully correct algorithm with correct division of arrays and sub-arrays, sorting and then merging the sub-arrays in merge sort
Rating B: Almost correct with error in one or two of division of arrays and sub-arrays, sorting and then merging the sub-arrays in merge sort
Rating C: Different sorting algorithm is used or no sorting algorithm is used
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to collect a positive integer n from the user, and then collect n character strings from the user (containing only lower case alphabets and no other characters, not even spaces). The strings need not be of equal length but the maximum length of any string should be 11. The strings should be stored in an appropriate 2D array. Your program should then include the following:

A function string_compare which takes two strings as input and returns 1 if the first string appears before the second string in alphabetical order, -1 if the second string appears before the first in alphabetical order, and 0 if the two strings are equal to each other. Do not use the inbuilt strcmp function.
A function string_sort which sorts the character strings using the mergesort algorithm taught in class. You are recommended to write a recursive implementation. You will automatically lose 50% of the marks for this program if you implemented the sorting within main.
Your program should then print out the strings in sorted alphabetical order, starting from the first to the last. Feel free to refer to the lecture slides for help.

Input Format
integer n, and a set of n character strings


Output Format
Print out the strings in the suggested order, one string on a new line


Constraints
n is a positive integer, n <= 15
For ease of display of the output, the maximum length of any of the strings should be 11, excluding the NULL character
The character strings should contain only lower case alphabets


Sample input and output




Input

Output

4

zebra

lion

tiger

monkey



lion

monkey

tiger

zebra







Note:  

Do not write any C++ statements for printing general messages. For example, the following should NOT be present in your program: 
cout << "Enter a number:",  
cout << "The computed answer is", etc.  


cout should be used to print only the computed final output. In addition, do not print unnecessary spaces unless specified in the program.

Student submission:
#include<iostream>
using namespace std;
int string_compare (char *first, char * second){
int i = 0;
while (true){
if (first[i] == 0 && second[i] == 0) return 0;
if (first[i] == 0) return +1;
if (second[i] == 0) return -1;
if (first[i] < second[i]) return +1;
if (first[i] > second[i]) return -1;
i++;
}
return 0;
}

int main(){
int n;
cin>>n;
char name[n][12];
for(int i=0;i<n;i++){
cin.getline(name[i], 12);} // terminated by ctrl-Z
cout<<string_compare(name[0], name[1]);}

Grading criterion: Merge sort algorithm
Rating A: Fully correct algorithm with correct division of arrays and sub-arrays, sorting and then merging the sub-arrays in merge sort
Rating B: Almost correct with error in one or two of division of arrays and sub-arrays, sorting and then merging the sub-arrays in merge sort
Rating C: Different sorting algorithm is used or no sorting algorithm is used
Rating D: 0
Assigned grade: C
Problem: Write a program that takes as input two complex numbers and performs one of the following operations on them: addition, subtraction, multiplication, or division. The output should be the result of the operation, with 3 digits after the decimal point. The input should be two pairs of floating-point numbers indicating the real and imaginary parts of the complex numbers, separated by spaces, followed by a letter indicating the operation to be performed. The output should be two space-separated numbers, with the real part followed by the imaginary part.

Student submission:
#include<simplecpp>
main_program{
	float real1,imag1, real2, imag2,p,q;
	char z;
	cin>>real1>>imag1>>real2>>imag2>>z;
	if(z=='A'){
		p= real1 + real2;
		q= imag1+imag2;
	}
	else if ( z=='S'){
		p=real1 - real2;
		q=imag1 -imag2;
	}
	else if( z=='M'){
		p=(real1*real2)-(imag1*imag2);
		q=( real1*imag2)+(real2*imag1);
	}
	else if(z=='D'){
		p=(( real1*real2)+( imag1* imag2))/(pow( real2,2)+pow( imag2,2));
		q=((imag2* real1)-(real1*imag2))/(pow(real2,2)+pow(imag2,2));
	}
	cout<<p;cout.precision(3);
        cout<<" ";
        cout<<q;cout.precision(3);	
}

Grading criterion: is division of complex numbers is correct implemented?
Rating A: if division of complex numbers is correctly written
Rating B: if the division of complex numbers is not correctly written
Rating C: 0
Rating D: 0
Assigned grade: B
Problem: Write a program that takes as input two complex numbers and performs one of the following operations on them: addition, subtraction, multiplication, or division. The output should be the result of the operation, with 3 digits after the decimal point. The input should be two pairs of floating-point numbers indicating the real and imaginary parts of the complex numbers, separated by spaces, followed by a letter indicating the operation to be performed. The output should be two space-separated numbers, with the real part followed by the imaginary part.

Student submission:
#include<simplecpp>
int main(){
	//taking inputs
	float x1,y1,x2,y2,x3,y3;
	cin >> x1 >> y1 >> x2 >> y2;
	char command;
	cin >> command;

	if(command=='A'){
		x3=x1+x2;
		y3=y1+y2;
	}
	if(command=='S'){
		x3=x1-x2;
		y3=y1-y2;
	}
	if(command=='M'){
		x3=x1*x2-y1*y2;
		y3=x1*y2+x2*y1;
	}
	if(command=='D'){
		x3=(x1*x2+y1*y2)/(x2*x2+y2*y2);
		y3=(x2*y1-x1*y2)/(x2*x2+y2*y2);
	}
	cout << fixed; cout.precision(3);
	cout << x3 << " " << y3;
}

Grading criterion: is division of complex numbers is correct implemented?
Rating A: if division of complex numbers is correctly written
Rating B: if the division of complex numbers is not correctly written
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: Write a program that takes as input two complex numbers and performs one of the following operations on them: addition, subtraction, multiplication, or division. The output should be the result of the operation, with 3 digits after the decimal point. The input should be two pairs of floating-point numbers indicating the real and imaginary parts of the complex numbers, separated by spaces, followed by a letter indicating the operation to be performed. The output should be two space-separated numbers, with the real part followed by the imaginary part.

Student submission:
#include<simplecpp>
main_program{
	float a,b,c,d; // a is r1,b is i1,c is r2,d is i2
	cin>>a>>b>>c>>d;
   char oper;
   cin>>oper;
   
   if(oper == 'A'){
	   	cout<<fixed;
		cout.precision(3);
	   cout<<a+c<<" "<<b+d;
   }
   if(oper == 'S'){
	   cout<<fixed;
	   cout.precision(3);
	   cout<<a-c<<" "<<b-d;
   }
   if(oper == 'M'){
	   cout<<fixed;
	   cout.precision(3);
	   cout<<a*c -b*d <<" "<<a*d + b*c;
   }
   if (oper == 'D'){
	   cout<<fixed;
	   cout.precision(3);
	   cout<<(a*c +b*d) /(c*c +d*d) <<" "<<(b*c -a*d)/(c*c +d*d);
   }
   cout<<endl;
}

Grading criterion: is division of complex numbers is correct implemented?
Rating A: if division of complex numbers is correctly written
Rating B: if the division of complex numbers is not correctly written
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: Write a program that takes as input two complex numbers and performs one of the following operations on them: addition, subtraction, multiplication, or division. The output should be the result of the operation, with 3 digits after the decimal point. The input should be two pairs of floating-point numbers indicating the real and imaginary parts of the complex numbers, separated by spaces, followed by a letter indicating the operation to be performed. The output should be two space-separated numbers, with the real part followed by the imaginary part.

Student submission:
#include<simplecpp>
main_program{
float a1, b1, a2, b2;
char x;
cin>> a1;
cin>> b1;
cin>> a2;
cin>> b2;
cin>>x;
cout<<fixed; cout.precision(3);
if(x=='A')
{cout<<a1+a2<<" "<<b1+b2<<endl;}
else if(x=='S')
{cout<<a1-a2<<" "<<b1-b2<<endl;}
else if(x=='M')
{cout<<(a1*a2)-(b1*b2)<<" "<<(a1*b2)+(a2*b1)<<endl;}
else if(x=='D')
{cout<<((a1*a2)+(b1*b2))/((a2*a2)+(b2*b2))<<" "<<((a2*b1)-(a1*b2))/((a2*a2)+(b2*b2))<<endl;
}
}

Grading criterion: is division of complex numbers is correct implemented?
Rating A: if division of complex numbers is correctly written
Rating B: if the division of complex numbers is not correctly written
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: Write a program that takes as input two complex numbers and performs one of the following operations on them: addition, subtraction, multiplication, or division. The output should be the result of the operation, with 3 digits after the decimal point. The input should be two pairs of floating-point numbers indicating the real and imaginary parts of the complex numbers, separated by spaces, followed by a letter indicating the operation to be performed. The output should be two space-separated numbers, with the real part followed by the imaginary part.

Student submission:
#include <simplecpp>
main_program {

     float a,b,p,q;

     cin >> a >> p >> b >> q;     //  a and b are Real & p and Img
     cout <<"A"<<endl;

      cout << a+b <<" "<< p+q <<" "<<endl;

      cout << fixed;
      cout.precision(3);     
}

Grading criterion: is division of complex numbers is correct implemented?
Rating A: if division of complex numbers is correctly written
Rating B: if the division of complex numbers is not correctly written
Rating C: 0
Rating D: 0
Assigned grade: B
Problem: Write a program that takes as input two complex numbers and performs one of the following operations on them: addition, subtraction, multiplication, or division. The output should be the result of the operation, with 3 digits after the decimal point. The input should be two pairs of floating-point numbers indicating the real and imaginary parts of the complex numbers, separated by spaces, followed by a letter indicating the operation to be performed. The output should be two space-separated numbers, with the real part followed by the imaginary part.

Student submission:
#include<simplecpp>
main_program{
	float real1, imag1, real2, imag2;
	
	char r; // A, S, M, D;
	
	cin>>real1>>imag1>>real2>>imag2>>r;

	if(r=='A'){
		float k=real1+real2;
		cout<<fixed;
		cout.precision(3);
		cout<<k<< " "<<(imag1+imag2)<<endl;}

	else if(r=='S'){
		cout<<fixed;
		cout.precision(3);
		cout<<(real1-real2)<<" "<<(imag1-imag2)<<endl;}
	else if(r=='M'){
		cout<<fixed;
		cout.precision(3);
		cout<<(real1*real2-imag1*imag2)<< " "<< (real1*imag2+real2*imag1)<<endl;}
	else if(r=='D'){
		cout<<fixed;
		cout.precision(3);
		cout<<((real1*real2+imag1*imag2)/(real2*real2+imag2*imag2))<<" "<<((imag1*real2-imag2*real1)/(real2*real2+imag2*imag2))<<endl;}




}





























/*	switch(r){
		case A : {
			cout<<(real1+real2)<<" " <<(imag1+imag2)<<endl;
			break;
		}

		case S : {
			cout<<(real1-real2)<<" "<<(imag1-imag2)<<endl;
			break;}

		case M : {
			cout<<(real1*real2 - imag1*imag2)<<" "<<(real1*imag2 + real2*imag1)<<endl;
			break;}
		case D : {
			cout<<((real1*real2 + imag1*imag2)/(real2*real2 + imag2*imag2))<< " "<< ((real2*imag1 - imag2*real1)/(real2*real2+imag2*imag2))<<endl;
			break;}
	}}
	
*/

Grading criterion: is division of complex numbers is correct implemented?
Rating A: if division of complex numbers is correctly written
Rating B: if the division of complex numbers is not correctly written
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: Write a program that takes as input two complex numbers and performs one of the following operations on them: addition, subtraction, multiplication, or division. The output should be the result of the operation, with 3 digits after the decimal point. The input should be two pairs of floating-point numbers indicating the real and imaginary parts of the complex numbers, separated by spaces, followed by a letter indicating the operation to be performed. The output should be two space-separated numbers, with the real part followed by the imaginary part.

Student submission:
#include<simplecpp>
main_program{
	float real1,imag1,real2,imag2;
	
	cin>>real1>>imag1>>real2>>imag2;
	char X;
	cin>>X;
	float real,imag;
	if (X=='A'){
		real=real1+real2;
		imag=imag1+imag2;
	
	       cout<<fixed;
	       cout.precision(3);
		cout<<real<<" "<<imag;
	}
       
	 else if(X=='S'){
		real=real1-real2;
		imag=imag1-imag2;
		cout<<fixed;
		cout.precision(3);
		cout<<real<<" "<<imag;
	}
       else if (X=='M'){
		real=real1*real2-imag1*imag2;
		imag=real1*imag2 +real2*imag1;
		cout<<fixed;
		cout.precision(3);
		cout<<real<<" "<<imag;
	}
       else if (X=='D'){
              real=(real1*real2+imag1*imag2)/(real2*real2+imag2*imag2);
	      imag=(imag1*real2-imag2*real1)/(real2*real2+imag2*imag2);
	      cout<<fixed;
	      cout.precision(3);
	      cout<<real<<" "<<imag;

       }

}

Grading criterion: is division of complex numbers is correct implemented?
Rating A: if division of complex numbers is correctly written
Rating B: if the division of complex numbers is not correctly written
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: Write a program that takes as input two complex numbers and performs one of the following operations on them: addition, subtraction, multiplication, or division. The output should be the result of the operation, with 3 digits after the decimal point. The input should be two pairs of floating-point numbers indicating the real and imaginary parts of the complex numbers, separated by spaces, followed by a letter indicating the operation to be performed. The output should be two space-separated numbers, with the real part followed by the imaginary part.

Student submission:
#include<simplecpp>
main_program{
	float a,b,x,y,sum1,sum2,sub1,sub2,mul1,mul2,div1,div2;
	char w,A='A',S='S',D='D',M='M';
	
	cin >> a >> b >> x >> y;
	cin >> w;
	sum1=a+x;
	sum2=b+y;
	sub1=a-x;
	sub2=b-y;
	mul1=(a*x)-(b*y);
	mul2=(a*y)+(b*x);
	div1=((a*x)+(b*y))/((x*x)+(y*y));
	div2=((b*x)-(a*y))/((x*x)+(y*y));

	

	if(w==A)
	{	cout<<fixed;
		cout.precision(3);
		cout << sum1 << " " << sum2 << endl;
	}
	if(w==S)
	{	cout<<fixed;
		cout.precision(3);
		cout << sub1 << " " << sub2 << endl;
	}
	if(w==M)
	{	cout<<fixed;
		cout.precision(3);
		cout << mul1 << " " << mul2 << endl;
	}
	if(w==D)
	{	cout<<fixed;
		cout.precision(3);
		cout << div1 << " " << div2 << endl;
	}	
}

Grading criterion: is division of complex numbers is correct implemented?
Rating A: if division of complex numbers is correctly written
Rating B: if the division of complex numbers is not correctly written
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: Write a program that takes as input two complex numbers and performs one of the following operations on them: addition, subtraction, multiplication, or division. The output should be the result of the operation, with 3 digits after the decimal point. The input should be two pairs of floating-point numbers indicating the real and imaginary parts of the complex numbers, separated by spaces, followed by a letter indicating the operation to be performed. The output should be two space-separated numbers, with the real part followed by the imaginary part.

Student submission:
#include<simplecpp>

int

Grading criterion: is division of complex numbers is correct implemented?
Rating A: if division of complex numbers is correctly written
Rating B: if the division of complex numbers is not correctly written
Rating C: 0
Rating D: 0
Assigned grade: B
Problem: Write a program that takes as input two complex numbers and performs one of the following operations on them: addition, subtraction, multiplication, or division. The output should be the result of the operation, with 3 digits after the decimal point. The input should be two pairs of floating-point numbers indicating the real and imaginary parts of the complex numbers, separated by spaces, followed by a letter indicating the operation to be performed. The output should be two space-separated numbers, with the real part followed by the imaginary part.

Student submission:
#include <simplecpp>
main_program {
	float r1, i1, r2, i2;
	char mode;
	cin >> r1 >> i1 >> r2 >> i2 >> mode;
	cout<< fixed;
	cout.precision(3);
	switch (mode) {
		case 'A' :
			cout << r1 +r2 << " " << i1 + i2;
			break;
		case 'S' :
			cout << r1-r2 << " " << i1 - i2;
			break;
		case 'M' :
			cout << r1*r2 - i1*i2 << " " << r1*i2 + r2*i1;
			break;
		case 'D' :
			cout <<((r1*r2 + i1*i2)/(r2*r2 + i2*i2)) << " " << ((i1*r2 - i2*r1)/(r2*r2+i2*i2));
			break;
	}
}

Grading criterion: is division of complex numbers is correct implemented?
Rating A: if division of complex numbers is correctly written
Rating B: if the division of complex numbers is not correctly written
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: Write a program that takes as input two complex numbers and performs one of the following operations on them: addition, subtraction, multiplication, or division. The output should be the result of the operation, with 3 digits after the decimal point. The input should be two pairs of floating-point numbers indicating the real and imaginary parts of the complex numbers, separated by spaces, followed by a letter indicating the operation to be performed. The output should be two space-separated numbers, with the real part followed by the imaginary part.

Student submission:
#include<simplecpp>
main_program{
	float real1,imag1,real2,imag2;
	char operation;

	cin>> real1>>imag1>>real2>>imag2>>operation;
	
	cout<<fixed;
	cout.precision(3); // 3 decimal accuracy

	int op=operation;

	if (op==65){ //addition, ascii(A)=65
		cout<< real1+real2<<" "<<imag1+imag2;
	}
	else if (op==83){ //subtraction
		cout<<real1-real2<<" "<<imag1-imag2;
	}
	else if(op==77){ //multiplication
		cout<< real1*real2- imag1*imag2<<" "<< real1*imag2+real2*imag1;
	}
	else cout<<( real1*real2+ imag2*imag1)/(pow(real2,2)+pow(imag2,2))<<" "<<(real2*imag1-real1*imag2)/(pow(real2,2)+pow(imag2,2)); //division

}

Grading criterion: is division of complex numbers is correct implemented?
Rating A: if division of complex numbers is correctly written
Rating B: if the division of complex numbers is not correctly written
Rating C: 0
Rating D: 0
Assigned grade: A
Problem: Write a program that takes as input two complex numbers and performs one of the following operations on them: addition, subtraction, multiplication, or division. The output should be the result of the operation, with 3 digits after the decimal point. The input should be two pairs of floating-point numbers indicating the real and imaginary parts of the complex numbers, separated by spaces, followed by a letter indicating the operation to be performed. The output should be two space-separated numbers, with the real part followed by the imaginary part.

Student submission:
#include <simplecpp>
main_program {
	float i, xa, ya, xb, yb, x, y;
	char operation;
	cin >> xa >> ya >> xb >> yb >> operation;
	i=1*operation;
	if (i=65) {
		x=xa+ya;
		y=ya+yb;
	}
	if (i=83) {
		x=xa-xb;
		y=ya-yb;
	}
	if (i=77) {
		x=xa*xb;
		y=ya*yb;
	}
	if (i=68) {
		x=xa/xb;
		y=ya/yb;
	}
	cout << fixed;
	cout.precision(3);
	cout << x << " " << y << endl;
}

Grading criterion: is division of complex numbers is correct implemented?
Rating A: if division of complex numbers is correctly written
Rating B: if the division of complex numbers is not correctly written
Rating C: 0
Rating D: 0
Assigned grade: B
Problem: Write a program that takes as input two complex numbers and performs one of the following operations on them: addition, subtraction, multiplication, or division. The output should be the result of the operation, with 3 digits after the decimal point. The input should be two pairs of floating-point numbers indicating the real and imaginary parts of the complex numbers, separated by spaces, followed by a letter indicating the operation to be performed. The output should be two space-separated numbers, with the real part followed by the imaginary part.

Student submission:
#include<simplecpp>
main_program{
	
	float m,n,u,p;
	cin>>m>>n>>u>>p;
       
	char c;cin>>c;
	float x,y;
      
        if (c=='A') y=n+p; x=m+u;
	
        cout<<x<<" "<<y<<endl;
        


	

}

Grading criterion: is division of complex numbers is correct implemented?
Rating A: if division of complex numbers is correctly written
Rating B: if the division of complex numbers is not correctly written
Rating C: 0
Rating D: 0
Assigned grade: B