URGENT ! Need help with my assignment. need to pass up in 8 hours pls pls help

Write a C program that displays menu as shown below:


Menu

1. Calculate Grade
2. Multplicaion Table
3. Print Pyramid
4. Exit

Enter your choice (1-4) : ___




For examples:

If the user enters 1, the program should be able to calculate the grade of N numbers of students. The program that will read data for test1 score and test2 score for all the students. The output should contain the score of test1 and test2 and the grade for the average score of test1 and test2 and also the number of students with grade F based on the Table as given below. Display the output.

Table : Grade Table / Jadual : Jadual Gred

Average Score Grade

80 – 100 A
65 – 79 B
50 – 64 C
35 – 49 D
0 - 34 F


If the user enters 2, the program should ask to enter one integer value from 1 to 12 and then display the following multiplication table:

Example :
If input : 7
The output that will be displayed :
Muliplication of 7
1 X 7 = 7
2 X 7 = 14
.
.
.
12 X 7 = 84


If the user enters 3, the program should be able to display the pyramid using asterisks(*), where the size is form by countable lines. User will enter the total line. Display the output.


Display an error message if the user enters a number outside the range of 1 through 4 when selecting an item from the main menu. If the user enters 4, the program should end.

Output must be well presented.
C or C++? This is a C++ website.
this one is C but i use Dev C++
So I can do this assignment in C++? Or do I have to use C?
Last edited on
i think need to use C
Last edited on
Have anything written, or are you just looking for someone to do it for you?
Ok give me a sec.
Last edited on
i have only written this but dont know if its correct

#include<iostream> // for input and output
#include<string.h> // for string nama...
using namespace std; // for name space..

struct student // declare struct
{
string name,no_matric;
string sub_code[10],sub_name[10],sub_grade[10];
float credit_hour[10];
}student1;

main()
{
int credit_hours[10];
int sem,total_subject; //'b', 'a',total_credit_hours and total_point
//are removed
float value[10],gpa[10],get_point[10];
float cgpa;
float total_point_sem = 0; //Initialise value
int total_credit_hours_sem = 0; //Initialise value
cin.ignore();

cout << "\t\ ================ ";
cout << "\n\t\ STUDENT'S REKOD " << endl;
cout << "\t\ ================ " << endl;

cout << "\n ENTER STUDENT'S NAME : "; //Enter student's name
getline(cin,student1.name);
cout << " ENTER STUDENT'S MATRIC NUMBER : "; //Enter student's matric number
getline(cin,student1.no_matric);
cout << " ENTER TOTAL SEM TAKEN :"; //Total semester taken by the student
cin >> sem;

for(int a = 0; a< sem ; a++) //'a' declared as int in for()[newly added]
{
int b; //newly added line,'b' choose to add it here because, if not, error will be occured : 'b' for gpa[b] will become undefined...

int total_credit_hours = 0; //newly added
float total_point = 0; //newly added
cout << "\n ENTER SUBJECT TAKEN FOR SEM : " << a+1 << ":"; //Enter total number of subject taken for each sem
cin >> total_subject;
for(int b = 0; b< total_subject; b++) //loop for the courses
{
cin.ignore();
cout << " ENTER SUBJECT CODE : "; //Enter subject code
getline(cin,student1.sub_code[b]);
cout << " ENTER SUBJECT NAME : "; //Enter subject name
getline(cin,student1.sub_name[b]);
cout << " ENTER SUBJECT'S CREDIT HOUR : "; //Enter credit hours of the subject
cin >> student1.credit_hour[b];
cin.ignore();
cout << " ENTER SUBJECT GRED : "; //Enter grade gained by student for every subject
getline(cin,student1.sub_grade[b]);

if(student1.sub_grade[b]=="A")
value[b]=4;
else if(student1.sub_grade[b]=="A-")
value[b]=3.75;
else if(student1.sub_grade[b]=="B+")
value[b]=3.5;
else if(student1.sub_grade[b]=="B")
value[b]=3;
else if(student1.sub_grade[b]=="B-")
value[b]=2.75;
else if(student1.sub_grade[b]=="C+")
value[b]=2.5;
else if(student1.sub_grade[b]=="C")
value[b]=2;
else if(student1.sub_grade[b]=="C-")
value[b]=1.75;
else if(student1.sub_grade[b]== "D+")
value[b]=1.5;
else if(student1.sub_grade[b]=="D")
value[b]=1;
else
value[b]=0;

get_point[b] = student1.credit_hour[b] * value[b]; //multiply of credit hours and grade get for each subject
total_credit_hours +=student1.credit_hour[b]; //total cerdit hours for a sem
total_point += get_point[b]; //total points(multiple of credits hours and grade)get for a sem
}

gpa[b] = total_point / total_credit_hours; //calculate GPA for each sem

total_point_sem += total_point; //Total points(multiple of grade and credit hours) get for all semester

total_credit_hours_sem += total_credit_hours; //credits hour get for all semester
}

cgpa = total_point_sem / total_credit_hours_sem; //calculate CGPA

cout << "\n =================================================== ";
cout <<"\n NAME : " << student1.name << endl; //display name of student
cout <<" NO MATRIC : "<< student1.no_matric << endl;
for(int a = 0; a< sem ; a++) //Declaration of 'a' as int in for()
{
cout <<" SUBJECT CODE \t" << " SUBJECT NAME \t" << " SUBJECT CREDIT HOURS " <<endl;
for(int b=0; b<total_subject; b++) //Declaration of 'b' as int in for()
{
cout << " " << student1.sub_code[b] << " : " << student1.sub_name[b]<< " : " << student1.credit_hour[b] << endl;
}
cout << " GPA" <<a+1<< " : " <<gpa[a] << endl;
}
cout << " CGPA : "<<cgpa<<endl;

cout << "\n =================================================== ";

}
Almost done.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct student
{
	string name;
	int test1Score;
	int test2Score;
	double avgScore;
};

void calculateGrade(int);
void multiplicationTable(int);
void printPyramid(int);

int main()
{
	cout << "Main Menu" << endl;
	cout << "1. Calculate Grade" << endl;
	cout << "2. Multiplication Table" << endl;
	cout << "3. Print Pyramid" << endl;
	cout << "4. Exit" << endl;

	int i;
	cin >> i;
	if (i == 1)
	{
		cout << endl;
		cout << "Enter number of students:" << endl;
		cin >> i;
		calculateGrade(i);
	}
	else if (i == 2)
	{
		cout << endl;
		cout << "Enter an integer value between 1 and 12:" << endl;
		cin >> i;
		multiplicationTable(i);
	}
	else if (i == 3)
	{
		cout << endl;
		cout << "Enter number of lines:" << endl;
		cin >> i;
		printPyramid(i);
	}
	else if (i == 4)
		return 0;
	else
	{
		cout << "Error. Invalid input." << endl;
		return 0;
	}

	// Comment out this line if not using windows.
	system("PAUSE");
	return 0;
}

void calculateGrade(int i)
{
	// Vector of students to store their test scores and average scores.
	vector<student> studvec;
	cout << endl;

	// Load the vector with student data.
	for (int j = 1; j <= i; ++j)
	{
		student stud;
		cout << "Enter student #" << j << " name:" << endl;
		cin >> stud.name;
		cout << "Enter student #" << j << " Test1 score:" << endl;
		cin >> stud.test1Score;
		cout << "Enter student #" << j << " Test2 score:" << endl;
		cin >> stud.test2Score;
		stud.avgScore = stud.test1Score + stud.test2Score / 2;
		studvec.push_back(stud);
	}

	// Cycle through the vector to output the student's test scores and figure out their letter grade based off of their average score.
	for (vector<student>::iterator i = studvec.begin(); i != studvec.end(); ++i)
	{
		char c;
		if (i->avgScore <= 100 && i->avgScore >= 80)
			c = 'A';
		else if (i->avgScore <= 79 && i->avgScore >= 65)
			c = 'B';
		else if (i->avgScore <= 64 && i->avgScore >= 50)
			c = 'C';
		else if (i->avgScore <= 49 && i->avgScore >= 35)
			c = 'D';
		else
			c = 'F';

		cout << endl;
		cout << i->name << "\nTest score #1: " << i->test1Score << "\nTest score #2: " << i->test2Score << endl;
		cout << i->name << " Grade average: " << c << endl;
	}

	// Display the total number of students who have a failing grade.
	int numFailures = 0;
	for (vector<student>::iterator i = studvec.begin(); i != studvec.end(); ++i)
	{
		if (i->avgScore <= 34 && i->avgScore >= 0)
			++numFailures;
	}
	cout << endl;
	cout << "Number of students failed: " << numFailures << endl;
}

void multiplicationTable(int i)
{
	cout << "Multiplication of " << i << endl;
	for (int j = 1; j <= 12; ++j)
		cout << j << "\t*\t" << i << "\t=\t" << j * i << endl;
}

void printPyramid(int i)
{
	// Starts a new line on every loop iteration.
	for (int j = 1, k = 0; j <= i; ++j, k = 0)
	{
		for (int space = 1; space <= i - j; ++space)
			cout << "  ";
		while (k != 2 * j - 1)
		{
			cout << "* ";
			++k;
		}
		cout << endl;
	}
}
Last edited on
omg man thank you so much HandsomeJohn , you're a life saver man really thank you thank you , i owe you man.
Read the code carefully and try to understand it all. Tweak it, play with it, and you'll understand it.
for (auto i = studvec.cbegin(); i != studvec.cend(); ++i)

this command line got error
ill try to fix it
I edited the post. Try it now.
Earlier of versions of C++ don't support cbegin or cend,
so I changed them to begin and end.
these are the errors

line col

84 12 [Error] 'i' does not name a type

84 33 [Error] expected ';' before 'i'

84 35 [Error] no match for 'operator!=' (operand types are 'int' and 'std::vector<student>::iterator {aka __gnu_cxx::__normal_iterator<student*, std::vector<student> >}')
its okay man HandsomeJohn , ill try to fix it. Thank you very much for the help :))
Lol man you gotta get a newer version of C++.
Just edited it again.
The C++ keyword "auto" also isn't supported in earlier versions of C++,
so I changed "auto" to "vector<student>::iterator"
i see so i need to update my dev c++ lol ,
alright it works perfectly now thanks man
i will play with it so ill understand it more lol
thank you so much man for the help , :)))
i really owe you man
Wait. This is C++ program rather than C. also it uses c++11 features.
c program must use printf and stdio.h.
Last edited on
Topic archived. No new replies allowed.