CSC138 - Coding
CSC138 - Coding
CSC
CSC 128
128
Fundamental OF
FUNDAMENTAL Of COMPUTER
Computer
Problem Solving
PROBLEM SOLVING
PAST EXAM
ASSIGNMENT
PAST YEAR
for(int m=0;m<size;m++)
{ if(sales[m]>highest)
{ highest=sales[m];
index=m;} }
for(int t=0;t<size;t++)
{ if(sales[t]%2!=0)
{ oddNum++;} }
for(int s=0;s<size;s++)
{ if(sales[s]%2!=0)
{ sumOdd+=sales[s]; } }
avg=sumOdd/10;
cout<<"Item that is lower than average : ";
for(int h=0;h<size;h++)
2
{ if(sales[h]<avg)
{ cout<<"\t"<<sales[h]; } }
3
QUESTION 22
QUESTION
#include <iostream>
using namespace std;
int main()
{
int array[30],total=0,count20=0;
for(int h=0;h<30;h++)
{ cout<<"Enter a number (30 even number) : ";
cin>>array[h]; }
for(int i=0;i<30;i++)
{ total+=array[i]; }
for(int j=0;j<30;j++)
{ if(array[j]==20)
count20++; }
cout<<"The total of all array summation :"<<total<<endl;
cout<<"The amount of 20 : "<<count20<<endl;
}
4
QUESTION 33
QUESTION
#include <iostream>
using namespace std;
int main()
{
double marks[7], hold, large=-999;
cout<<"Please enter your marks : ";
for(int i=0;i<7;i++)
{ cin>>marks[i]; }
cout<<endl;
for(int i=1;i<7;i++)
{ for(int j=0;j<(7-i);j++)
{if(marks[j]>marks[j+1])
{ hold=marks[j+1];
marks[j+1]=marks[j];
marks[j]=hold; } } }
for(int i=0;i<7;i++)
{ cout<<marks[i]<<" "; }
cout<<endl<<endl; }
5
QUESTION 44
QUESTION
#include <iostream>
using namespace std;
void findNumOfStudents(double arr[],int size);
double findAverage(double arr[],int size);
double findHighest(double arr[],int size);
int searchScore(double arr[],int size,int search);
void sortScore(double arr[],int size);
int main()
{
int size=10;
double score[10]={55.0,67.0,52.5,70.5,82.0,31.0,88.0,64.5,55.0,89.0};
double average,highest;
int location,search;
findNumOfStudents(score,10);
average=findAverage(score,10);
cout<<"Average score is : "<<average<<endl;
highest=findHighest(score,10);
cout<<"Highest score is : "<<highest<<endl;
6
if(score[i]<=59 && score[i]>=0)
{ getF++; } }
cout<<"Student that get A is : "<<getA<<endl;
cout<<"Student that get B is : "<<getB<<endl;
cout<<"Student that get C is : "<<getC<<endl;
cout<<"Student that get D is : "<<getD<<endl;
cout<<"Student that get F is : "<<getF<<endl; }
for(int i=0;i<size;i++)
{ cout<<score[i]<<" "; }
cout<<endl; }
7
8
QUESTION
QUESTION55
#include<iostream>
using namespace std;
void insertMark(double arr[],int size);
double calcTotal(double arr[],int size);
int main()
{
int size=5;
double marks[5];
double total=0;
insertMark(marks,size);
total=calcTotal(marks,size);
cout<<"\nThe total marks is : "<<total<<endl;
}
9
QUESTION
QUESTION 66
#include<iostream>
using namespace std;
int main()
{
float money[7];
float total=0, highest=-999;
int day=1;
for(int i=0;i<7;i++)
{ cout<<"Enter amount of payment for Day "<<day<<" : ";
cin>>money[i];
day++; }
for(int c=0;c<7;c++)
{ if(money[c]>highest)
{ highest=money[c]; } }
cout<<"\nThe highest total payment received by the Clinic is : "<<highest<<endl;
}
10
QUESTION 1
#include<iostream>
using namespace std;
struct carrymark
{ char name[100];
int id;
float test1;
float test2;
float quiz;
float assignment;
float total_mark; };
int main()
{ carrymark studentmark;
cout<<"Insert student name:";
cin.getline(studentmark.name,100);
cout<<"insert student id:";
cin>>studentmark.id;
cout<<"insert test 1:";
cin>>studentmark.test1;
cout<<"insert test 2:";
cin>>studentmark.test2;
cout<<"insert quiz mark:";
cin>>studentmark.quiz;
cout<<"insert assignment mark:";
cin>>studentmark.assignment;
studentmark.total_mark=(studentmark.test1/0.5*0.1)+(studentmark.test2/0.5*0.1)+(stu
dentmark.quiz/0.5*0.1)+(studentmark.assignment/0.5*0.1);
cout<<"student name : "<<studentmark.name<<endl;
cout<<"student id : "<<studentmark.id<<endl;
cout<<"test 1 mark : "<<studentmark.test1<<endl;
cout<<"test 2 mark : "<<studentmark.test2<<endl;
cout<<"Quiz mark : "<<studentmark.quiz<<endl;
cout<<"assignment mark : "<<studentmark.assignment<<endl;
cout<<"total carry mark : "<<studentmark.total_mark<<endl; }
1
1
QUESTION 1
2
2
QUESTION 2
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
int main()
{ ifstream infile;
ofstream outfile1;
ofstream outfile2;
infile.open("itemInfo.txt");
outfile1.open("Computer.txt");
outfile2.open("Others.txt");
char code[40];
char type[40];
char descp[40];
double price;
if(!infile)
{ cout<<"Error: File Doesn't Exist!'"<<endl; }
else
{ coutfile1<<" COMPUTER "<<endl;
coutfile2<<" OTHERS "<<endl; }
while(!infile.eof())
{ infile.getline(code,40,';');
infile.getline(type,40,';');
infile.getline(descp,40,';');
infile>>price;
if(strcmp(type,"COMPUTER")==0)
outfile1<<code<<" "<<descp<<" "<<price<<endl;
else
outfile2<<code<<" "<<descp<<" "<<price<<endl; }
cout<<"Processing Data"<<endl; }
infile.close();
outfile1.close();
outfile2.close(); }
3
3
QUESTION 2
4
4
COMPUTER
OTHERS
5
5
QUESTION 3
#include <iostream>
#include <fstream>
using namespace std;
int main()
{ ifstream infile;
ofstream outfile1;
ofstream outfile2;
infile.open("SUKSIS.txt");
outfile1.open("PASS.txt");
outfile2.open("FAIL.txt");
char name[50];
char gender;
int weight;
double height,BMI;
if (!infile)
{ cout<<"NO File IS Found~!"; }
else
{ while(!infile.eof())
{ infile.getline(name,50,'#');
infile>>gender;
infile>>weight;
infile>>height;
BMI=(weight/(height*height));
if(gender=='M')
{
if(weight>=50)
{
if(height>=1.63)
{
if(BMI>=18.0 && BMI<=23.0)
{
outfile1<<name<<" "<<gender<<" "<<weight<<" "<<height<<endl;}
else
6
6
outfile2<<name<<" "<<gender<<" "<<weight<<" "<<height<<endl; }
else
outfile2<<name<<" "<<gender<<" "<<weight<<" "<<height<<endl; }
else
outfile2<<name<<" "<<gender<<" "<<weight<<" "<<height<<endl; }
else
if(gender=='F')
{ if(weight>=48)
{ if(height>=1.57)
{ if(BMI>=18.0 && BMI<=23.0)
{
outfile1<<name<<" "<<gender<<" "<<weight<<" "<<height<<endl;}
else
7
7
QUESTION 3
8
8