For Copy Pasting Codes: copyable codes are at the end of this post, scroll to the bottom.
For Input and Output just select and drag-drop the "input format" and "output format" text from the questions. (edit a little if you have time.)
For Input and Output just select and drag-drop the "input format" and "output format" text from the questions. (edit a little if you have time.)
count Words in Tweets
Code:
Psuedocode:
startinput w
count =0
untill eof
input s
count=count + number of w in s
end loop
output count
stop
____________________________________________________________________________________________________________________
Sort Data in File
Code:
Psuedocode:
startinput numbers into array
sort numbers in array
output elements in array
stop
____________________________________________________________________________________________________________________
Special Pay Increase Problem
Code:
Psuedocode:
startloop until end of file
input name1,name2,salary,increase
output name1,name2,salary*(1+ increase/100)
end loop
stop
____________________________________________________________________________________________________________________
Code Detection Problem
Code:
Psuedocode:
startloop until eof:
input n
input n elements in to array1
input z
if n=z
input n elements in to array2
if n!=z or array1!=array 2
output Message transmitted is not ok
else output Message transmitted is ok
end loop
stop
____________________________________________________________________________________________________________________
Class Average Problem
Code:
Psuedocode:
startloop until end of file:
input n,m,t
mt=mt+m; tt=tt+t; at=at + m/t;
output n,m,t,m/t
end loop
output mt,tt,at
stop
-----------------------------------------------------------------------------------------------------------------------------------------
CODES FOR COPY-PASTING (in same order as above. seperated by a line of underscores)
#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
int main(){
ifstream f("tweets.txt");
char w[10],s[50]; int c=0;
cin>>w;f>>s;
while(!f.eof()){
c+=strcmp(w,s)?0:1;
f>>s; }
cout<<c;
}
____________________________________________________________________
#include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
int main(){
char s[20];cin>>s;
ifstream f(s);
int v[100],i=0;
while(!f.eof()) f>>v[i++];
sort(v,&v[i]);
for(int z=0;z<i;z++)cout<<v[z]<<"\n";
}
_____________________________________________________________________
#define e employee
void e::get(ifstream& i){i>>lastName>>firstName>>salary>>inc;}
void e::print(){cout<<fixed<<setprecision(2)<<lastName<<"\n"<<firstName<<"\n"<<updated_Salary<<"\n";}
void e::update_Sal(){updated_Salary=salary*(1+inc/100);}
int main(){
char s[20];cin>>s;
ifstream f(s); e x;
while(!f.eof()){
x.get(f); x.update_Sal(); x.print();
}
}
__________________________________________________________
#include<iostream>
#include<fstream>
using namespace std;
int main(){
char s[20];cin>>s;
int n,a[30],z,i,t,g;
ifstream f(s);
while(!f.eof()){
f>>n;
for(i=0;i<n;i++)f>>a[i];
g=0; f>>z;
for(i=0;i<z;i++){ f>>t; if(z!=n||t!=a[i])g=1;}//short circuit so np..
cout<<"Message transmitted"<<(g?" is not ":" ")<<"ok\n";}
}
_____________________________________________________________
#include<iostream>
#include<fstream>
using namespace std;
int main(){
char s[20]; cin>>s;
ifstream f(s);
int n; float m,t,mt=0,tt=0,at=0,i=0;
while(!f.eof()){
f>>n>>m>>t;
mt+=m;tt+=t;at+=m/t;i++;
printf("%d\t%.2f\t%.2f\t%.2f\n",n,m,t,m/t);}
printf("%.2f\n%.2f\n%.2f\n%.2f",mt,tt,at,at/i);
f.close();
}
#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
int main(){
ifstream f("tweets.txt");
char w[10],s[50]; int c=0;
cin>>w;f>>s;
while(!f.eof()){
c+=strcmp(w,s)?0:1;
f>>s; }
cout<<c;
}
____________________________________________________________________
#include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
int main(){
char s[20];cin>>s;
ifstream f(s);
int v[100],i=0;
while(!f.eof()) f>>v[i++];
sort(v,&v[i]);
for(int z=0;z<i;z++)cout<<v[z]<<"\n";
}
_____________________________________________________________________
#define e employee
void e::get(ifstream& i){i>>lastName>>firstName>>salary>>inc;}
void e::print(){cout<<fixed<<setprecision(2)<<lastName<<"\n"<<firstName<<"\n"<<updated_Salary<<"\n";}
void e::update_Sal(){updated_Salary=salary*(1+inc/100);}
int main(){
char s[20];cin>>s;
ifstream f(s); e x;
while(!f.eof()){
x.get(f); x.update_Sal(); x.print();
}
}
__________________________________________________________
#include<iostream>
#include<fstream>
using namespace std;
int main(){
char s[20];cin>>s;
int n,a[30],z,i,t,g;
ifstream f(s);
while(!f.eof()){
f>>n;
for(i=0;i<n;i++)f>>a[i];
g=0; f>>z;
for(i=0;i<z;i++){ f>>t; if(z!=n||t!=a[i])g=1;}//short circuit so np..
cout<<"Message transmitted"<<(g?" is not ":" ")<<"ok\n";}
}
_____________________________________________________________
#include<iostream>
#include<fstream>
using namespace std;
int main(){
char s[20]; cin>>s;
ifstream f(s);
int n; float m,t,mt=0,tt=0,at=0,i=0;
while(!f.eof()){
f>>n>>m>>t;
mt+=m;tt+=t;at+=m/t;i++;
printf("%d\t%.2f\t%.2f\t%.2f\n",n,m,t,m/t);}
printf("%.2f\n%.2f\n%.2f\n%.2f",mt,tt,at,at/i);
f.close();
}
No comments:
Post a Comment